Can I use RequireJS 2 to reload a recently updated.js file? Here is my use case:
alert("abc")
;Foo.Bar()
and get an alert thing with "abc"alert("def")
Foo.Bar()
, I get the alert with "def"Thank you!
You can acess the chome console by pressing: Ctrl+Shift+J And going to the "Console" Tab.
There Type the following:
var script = document.createElement("script");
script.src = "Path to Js File";
document.body.appendChild(script);
It should update the JavaScript file without reloading the whole page.
- Path to file Could be:
1) http/s://yourdomain.com/path/jsfile.js
2) file://path/jsfile.js - (Local file system)
Note:
The method used above does not require the RequireJS Library.
As you need to (load AND refresh) the js file, I suggest to define a function in your base javascript file like
function reloadJS(file) {
var script = document.createElement("script");
script.src = "/" + file + ".js";
myWindow = window.open(script.src + "?v=" + Math.random());
document.body.appendChild(script);
myWindow.close();
}
and call it from console like reloadJS("myjsfilename")
this will reload the js file and force it to update the file for browser.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.