Speed up page loads, defer your JavaScript

  • Post author:
  • Post category:Uncategorized

A coworker of mine showed me something today that looks interesting. Say you’ve got a page with a lot of client site JS code that runs AFTER the page is loaded. Things like form validation, Ajax functions, stuff like that. Well, apparently you can add a defer attribute to your script tag, and the browser will not load the JS file until AFTER the page has been fully loaded and displayed to the user. With JavaScript heavy sites, this could dramatically decrease page load times. Here’s an example:<script src=”script.js” type=”text/javascript” defer=”defer”></script>I am not sure if this works in all browsers, and I’m not sure if it causes any problems. If anybody has any experience with this, please drop me a comment.