JavaScript resources are parser-blocking so consider doing this to speed-up your JavaScript on your website:
- If the script does not affect the DOM tree (does not add or modifies HTML) and is not affecting stylesheets then you can put it inside external file, call it inside <head> element and add an “async” attribute
<head> ... <script src="analytics.js" async></script> ... </head>
- defer Javascript execution (The script tag can also take a
defer
attribute, in the same way that it can take anasync
attribute. The difference is that withdefer
, the script waits to execute until after the document has been parsed, whereasasync
lets the script run in the background while the document is being parsed.) - Minify, compress and Cache JS.
Leave A Comment
You must be logged in to post a comment.