Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How LiveReload (and other similar apps) work technically?

There are some great web-development tools out there which make life of developers easy. Apps like LiveReload and CodeKit are the great examples.

All I'm interested about them is the way they make web-page live reload in web browser (be it Chrome, Firefox or whatever) from within itself when file changes are written to hard-drive.

How they actually do it? Are there any APIs which web browser vendors expose to perform this? or its just custom server-side script which is injected to webpage (not actually wrote by web-developer) before it reaches browser, and some Ajax magic happens when the file is changed on the drive.

I'm planning to develop something like this in Python or Vala (Linux) and .NET (Windows), so please let me know if there is some documentation available to do this.

like image 442
Kushal Avatar asked Jun 10 '12 08:06

Kushal


1 Answers

From LiveReload FAQ:

To communicate with your browsers, LiveReloads needs its JavaScript code to be injected into your web pages. There are 3 ways to arrange that:

  1. either add a script tag into your HTML code manually, or
  2. install a browser extension (that, when activated, adds the script tag to the visited pages on the fly), or
  3. use a plugin for your web framework (that adds the script tag on the fly when serving requests), currently only available for Rails/Rack.

Also, I know this question is old, but for those who also got here searching for "livereload python", there's a great LiveReload server written in python.

like image 128
Gui Ambros Avatar answered Oct 06 '22 22:10

Gui Ambros