Auto-reload browser when I save changes to html file, in Chrome?

后端 未结 23 1949
半阙折子戏
半阙折子戏 2020-12-12 11:46

I\'m editing an HTML file in Vim and I want the browser to refresh whenever the file underneath changes.

Is there a plugin for Google Chrome that will listen for ch

相关标签:
23条回答
  • 2020-12-12 12:23

    There is a java app for os x and Chrome called Refreschro. It will monitor a given set of files on the local file system and reload Chrome when a change is detected:

    http://neromi.com/refreschro/

    0 讨论(0)
  • 2020-12-12 12:26

    A quick solution that I sometimes use is to divide the screen into two, and each time a change is made, click on the document xD .

    <script>
    document.addEventListener("click", function(){
        window.location.reload();
    })
    </script>
    
    0 讨论(0)
  • 2020-12-12 12:27

    Use Gulp to watch the files and Browsersync to reload the browser.

    The steps are:

    In the command line execute

    npm install --save-dev gulp browser-sync

    Create gulpfile.js with the following contents:

    var gulp = require('gulp');
    var browserSync = require('browser-sync').create();
    var reload = browserSync.reload;
    
    gulp.task('serve', function() {
      browserSync.init({
        server: {
          baseDir: "./"
        }
      });
    
      gulp.watch("*.html").on("change", reload);
    });
    

    Run

    gulp serve

    Edit HTML, save and see your browser reload. The magic is done through on-the-fly injection of special tag into your HTML files.

    0 讨论(0)
  • 2020-12-12 12:30
    pip install https://github.com/joh/when-changed/archive/master.zip
    
    alias watch_refresh_chrome=" when-changed -v -r -1 -s ./ osascript -e 'tell application \"Google Chrome\" to tell the active tab of its first window to reload' "
    

    then just enter the directory you want to monitor execute "watch_refresh_chrome"

    0 讨论(0)
  • 2020-12-12 12:32

    With the addition of a single meta tag into your document, you can instruct the browser to automatically reload at a provided interval:

    <meta http-equiv="refresh" content="3" >
    

    Placed within the head tag of your document, this meta tag will instruct the browser to refresh every three seconds.

    0 讨论(0)
  • 2020-12-12 12:32

    This can be done using a simple python script.

    1. Use pyinotify to monitor a particular folder.
    2. Use Chrome with debugging enabled. Refresh can be done via a websocket connection.

    Full details can be referred here.

    0 讨论(0)
提交回复
热议问题