Inline your JavaScript

Do your web pages load a single or several JavaScript files? Then there is a good chance you can speed your website up by optimizing the JavaScript delivery. Read more below.

How inlining JavaScript can benefit performance

Every time a visitor loads a web page in a browser they need to request, download and execute the JavaScript files in order to correctly load the page. These requests can be render-blocking, especially when there's a lot of them. Inlining (some of) the JavaScript will eliminate this problem as the browser no longer has to make multiple download requests, plus you allow the browser to instantly render the HTML page without having to load additional files. CSS files should preferably be inlined as well.

Only smaller JavaScript

When you have lots of (or very large) JavaScript files it’s better to still use a file to call them from your web page. The best practice for larger JavaScript is to place all of them in one bigger file. This way the browser only has to request one file instead of multiple, which speeds up your website due to the lower number of HTTP requests.

How to inline JavaScript

  • Copy the JavaScript you want to inline (remember, only smaller JavaScript) and combine all of theme into one bigger script
  • Place the script within <script type="text/javascript"></script> tags
  • Place all of it within the HTML </head></head> tags

Below is an example of how this may look: <head> <script type="text/javascript"> YOUR JAVASCRIPT </script> </head>

Compress JavaScript code

When you really want to optimize your JavaScript in the best way possible you can also compress them with the JavaScript Compressor. This compressor can be used to minimize the JavaScript size, combine multiple JavaScript files and detect errors.

Want To Have The Maximum Page Speed Possible For Your Website?

We can help with that! We have professionally optimized the speed of thousands of websites. Because of this we know how to get the best results quickly while keeping our prices low. Get an instant price quote for our services now.