How to Make JS Code Execute After the Page has Finished Rendering (Website Optimization)
Written by Richi González Wednesday, 9 January 2013
When I’m creating a website, I try to make it load as fast as possible. I have read lots of techniques on how to achieve this, and the one that is effortless and free to make it, is having JS code run after the DOM is ready.
1. Open the file where your JS code resides. For this article, I will have the following code between my <head> tags:
So our code will look like this:
Now the big question: why would I want the JS code to load at the end and not immediately after the user visits the page? Because if we have lots of JS code, the page won’t render until the JS is executed, so if you load the JS at the end, the user can use the website while the JS code is loading.
Hope that was clear enough. If you have any question, comment or suggestion, please do not hesitate to contact me and I’ll be more than glad to assist you.
Owner of Juapo2Services
Looking for quality web hosting? Look no further than Arvixe Web Hosting!