Skip navigation

Tag Archives: debug

JavaScript can be loaded dynamically on the fly to improve the performance of the page. Basically it is used as lazy loading without blocking other important content of the page.

Here is the code snippet

var fileref=document.createElement('script')
fileref.setAttribute("src", "myscript.js")
if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref)

One issue with this approach is that you can’t see myscript.js in chrome’s sources tab if you want to debug.

Place a comment at the end of the script like below
//@ sourceURL=myscript.js


Hope this helps.


Do you need a meaningful error report?

onerror = handleErr;
var errorText = "";
function handleErr(msg, url, l) {
   errorText = "There was an error on this page.\n\n";
   errorText += "Error: " + msg + "\n";
   errorText += "URL: " + url + "\n";
   errorText += "Line: " + l + "\n\n";
   errorText += "Click OK to continue.\n\n";
   return true;

While testing in IE, it will give you more hints.

update (on 19th December 2013): Now a days IEs shipping with powerful debuggers.