Skip to content

Instantly share code, notes, and snippets.

@maheshsenni
Created May 12, 2016 01:08
Show Gist options
  • Save maheshsenni/4fecafc3e26c8f694624165e7de03805 to your computer and use it in GitHub Desktop.
Save maheshsenni/4fecafc3e26c8f694624165e7de03805 to your computer and use it in GitHub Desktop.
Step 3b - Creating a module bundler with Hot Module Replacement
/* This file is included in the page running the app */
(function() {
// create an instance of Socket.IO for listening
// to websocket messages
var socket = io();
// listen for 'file-change' message
socket.on('file-change', function(msg) {
console.log('File changed: ' + msg.id);
// download the updated module to kick start
// hot module replacement
downloadUpdate(msg.id);
});
function downloadUpdate(id) {
// create a new script tag and add it to the page
// to make a JSONP request to /hot-update
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.type = "text/javascript";
script.charset = "utf-8";
script.src = "/hot-update?id=" + id;
head.appendChild(script);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment