Documentation

Getting started

  1. Install the browser plugin «Live Reload Browser Page» version you need:
  2. Set up your tool (Gulp, Webpack, Grunt or other.):

Browser plugin API

Description

The server requires use the WebSocket protocol.
Server
←→
Client (browser plugin)
When the server is started and the connection is established with the browser plugin, the following requests can be used on the server.

Request data

Structure


  {
    action: value,
    partial_reload: {
      tag: value,
      src: value,
      href: value,
      execute_before: value,
      execute_after: value,
      reloadPageIfResNotExists: value,    
      html: {
        force_load_images: value
      },
      js: {
        resetHTML: value,
        clear_obsolete_tags: value,
        use_method_1: {
          send_event_onload: value,
        },
        use_method_2: value,
        use_method_3: {
          check_loaded_successful: value 
        }
      }
    }
  }  

KeyRequiredTypeDescription
actionrequiredStringThis value page_reload - reloads the browser page.
partial_reloadoptionalObjectReloads elements of a browser page without completely reloading the page. You can reload separately: CSS, HTML or JavaScript.
partial_reload
KeyRequiredTypeDescription
tagrequiredString
link - reloads <link>.
script - reloads <script>.
html (experimental) - reloads HTML (the first request downloads all resources completely. All subsequent requests only update HTML.).
srcrequired for reload scriptStringThe path to the file specified in the src <script>. As example: /build/js/index.js
hrefrequired for reload linkStringThe path to the file specified in the href <link>. As example: /build/style/index.css
execute_beforeoptionalStringFunction execution before partial reload. As example:

var before_Style = function(){
    // Code
}.toString();
                
execute_afteroptionalStringFunction execution after partial reload. As example:

var after_Style = function(){
    // Code
}.toString();
                
reloadPageIfResNotExistsoptionalBooleantrue - full reload of a browser page when a resource is not found.
Works with partial_reload.tag: 'link'.
Works with partial_reload.tag: 'script' but only with partial_reload.js.use_method_1.
htmloptionalObjectOptions for HTML reloading.
jsrequired for reload scriptObjectOptions for JavaScript reloading.
partial_reload.html
KeyRequiredTypeDescription
force_load_imagesoptionalBooleantrue - forces reloads of images on the page. Usually, images are taken from the browser cache when the HTML is partially reloaded. Default is false.
partial_reload.js
KeyRequiredTypeDescription
resetHTMLoptionalBooleantrue - reset HTML to initial state, after Javascript changed it.
Default is false.
clear_obsolete_tagsoptionalArrayMarks the desired HTML tags with a marker before reloading, and deletes them after a JavaScript reload. As example: ['style', 'link'] - obsolete versions of <styles> tags and <link> will be removed. This option may be needed when dynamically adding <styles>, <link> or other tags.
use_method_1required if other method is not definedBoolean|Objecttrue or {} - recreates a HTML node <script>. Global variables will not be removed. Event listeners will not be removed.
use_method_2required if other method is not definedBooleantrue - (experimental) - First loads a <script> and then updates the HTML. Global variables will not be removed. Event listeners will be removed.
use_method_3required if other method is not definedObject|Booleantrue or {} (experimental) - updates HTML with modification (a timestamp is added to the path to a <script>. As the timestamp is added, old scripts remain in the cache until the browser page is closed).
partial_reload.js.use_method_1
KeyRequiredTypeDescription
send_event_onloadoptionalBooleantrue - send onload event after script reload. Default is false.
partial_reload.js.use_method_3
KeyRequiredTypeDescription
check_loaded_successfuloptionalBooleantrue - checks if the script has loaded. This check can slow down the loading speed of the script. Default is false.

Examples

Full reload of the browser page.

  const page_reload_data = {
    action: 'page_reload'
  };

  // client.send(JSON.stringify(page_reload_data));

Reload only <link> tag.

  const page_reload_data = {
    action: 'page_reload',
    partial_reload: {
      tag: 'link',
      href: '/build/style/index.css'
    }
  }; 

  // client.send(JSON.stringify(page_reload_data));

Reload only HTML.

  const page_reload_data = {
    action: 'page_reload',
    partial_reload: {
      tag: 'html',    
      html: {
        force_load_images: true
      }
    }
  };

  // client.send(JSON.stringify(page_reload_data));

Reload only <script>.

  const page_reload_data = {
    action: 'page_reload',
    partial_reload: {
      tag: 'script',
      src: '/build/js/index.js',    
      js: {
        clear_obsolete_tags: ['style'],
        use_method_1: {
          send_event_onload: true
        }
      }
    }
  };

  // client.send(JSON.stringify(page_reload_data));

Reload only <script>.

  const page_reload_data = {
    action: 'page_reload',
    partial_reload: {
      tag: 'script',
      src: '/build/js/index.js',    
      js: {
        resetHTML: true,
        use_method_2: true
      }
    }
  };

  // client.send(JSON.stringify(page_reload_data));

Reload only <script> and use execute_before.

  let before = function(){
    let $script1 = document.getElementById("script1");
    if($script1 != null){
        $script1.innerHTML = '';
    }
  }.toString();

  const page_reload_data = {
    action: 'page_reload',
    partial_reload: {
      tag: 'script',
      src: '/build/js/index.js', 
      execute_before: before,   
      js: {
        use_method_2: true
      }
    }
  };

  // client.send(JSON.stringify(page_reload_data));