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

后端 未结 23 1948
半阙折子戏
半阙折子戏 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:15

    I assume you're not on OSX? Otherwise you could do something like this with applescript:

    http://brettterpstra.com/watch-for-file-changes-and-refresh-your-browser-automatically/

    There is also a plugin for chrome called "auto refresh plus" where you can specify a reload every x seconds:

    https://chrome.google.com/webstore/detail/auto-refresh-plus/oilipfekkmncanaajkapbpancpelijih?hl=en

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

    I know this is an old question but in case it helps someone, there is a reload npm package that solves it.

    In case that you are not running it on a server or have received the error Live.js doesn't support the file protocol. It needs http.

    Just install it:

    npm install reload -g
    

    and then at your index.html directory, run:

    reload -b
    

    It will start a server that will refresh every time you save your changes.

    There are many other options in case you're running it on the server or anything else. Check the reference for more details!

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

    In node.js, you can wire-up primus.js (websockets) with gulp.js + gulp-watch (a task runner and change listener, respectively), so that gulp lets your browser window know it should refresh whenever html, js, etc, change. This is OS agnostic and I have it working in a local project.

    Here, the page is served by your web server, not loaded as a file from disk, which is actually more like the real thing.

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

    Offline solution using R

    This code will:

    • setup a local server using the given .html-file
    • return the server adress, so that you can watch it in a browser.
    • make the browser refresh everytime a change is saved to the .html-file.

      install.packages("servr")
      servr::httw(dir = "c:/users/username/desktop/")
      

    Similar solutions exist for python etc.

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

    Handy Bash one-liner for OS X, assuming that you have installed fswatch (brew install fswatch). It watches an arbitrary path/file and refreshes the active Chrome tab when there are changes:

    fswatch -o ~/path/to/watch | xargs -n1 -I {} osascript -e 'tell application "Google Chrome" to tell the active tab of its first window to reload'
    

    See more about fswatch here: https://stackoverflow.com/a/13807906/3510611

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

    http://livereload.com/ - native app for OS X, Alpha version for Windows. Open sourced at https://github.com/livereload/LiveReload2

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