javascript Live Reload

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Live Reload相关的知识,希望对你有一定的参考价值。

/*=================================================================
 Live Reload Script to inject live .inc files during concepting
=================================================================*/

function liveINC() {
  var all, i, item, file, xhttp;
  all = document.getElementsByTagName("*");
  for (i = 0; i < all.length; i++) {
      item = all[i];
      file = item.getAttribute("live-file");
      if (file) {
          xhttp = new XMLHttpRequest();
          xhttp.onreadystatechange = function () {
              if (this.readyState == 4) {
                  item.innerHTML = this.responseText;
                  item.removeAttribute("live-file");
                  liveINC();
              } 
          }
          xhttp.open("GET", file, true);
          xhttp.send();
          
          return;
      }
  }
  console.log("Running live reload script....");
}

/*=====================================================================
 Remove Reload when not doing active development
 Also allows for browser-sync to inject changes during dev process
======================================================================*/

if(location.hostname != "localhost") {
  console.log("Not Live Reloading File... :(");
  document.getElementById("inc").removeAttribute("live-file");
} else {
  console.log("Live Reloading! :)")
  setTimeout(function() {
      $('head').append('<link href="http://localhost:3000/css/master.css" rel="stylesheet" type="text/css" />')
      $('head').append('<link href="../../global/CSS/global.css" rel="stylesheet" type="text/css" />')
      $('link[href*="/sitefiles/2590/css/master.css"]').remove();
  })
}

以上是关于javascript Live Reload的主要内容,如果未能解决你的问题,请参考以下文章

javascript Live Reload Script

javascript Live Reload

text phpstorm live-reload for domain

React Native入门 Enable live Reload

如何在运行 React Native 应用程序的 iOS 设备中启用 Live Reload?

live-server的使用