Advice on how to improve your page speed can be a double-edged sword. For one thing, a lot of people who write these articles don’t know what it’s like to actually run a medium-sized or large website with even a little bit of complexity. If they did, they wouldn’t be so confident in their recommendations. The truth is that there’s no “one size fits all” approach when it comes to making your pages load faster. While some improvements can be made for free, others come with tradeoffs.
To make matters worse, outdated advice persists. For example, I’d written earlier about how it was no longer a good idea to combine JS and CSS files. That advice made sense in an earlier time when browsers were unable to download multiple files in parallel beyond a certain point. But with HTTP/2, those restrictions were removed and now combining CSS or JS in this way is actively harmful. But still you see people giving the same advice over and over.
The Original Purpose of Moving JS to the Footer
The reason why inline JS is problematic, is that it can reference a JS function that’s defined only later in the footer. Here’s a screenshot of what it looks like when a JS file is deferred to the footer with an inline JS reference to it:
In this screenshot, the “anchorific” function present in inline JS is only defined later on in an external JS file that’s loaded in the footer.
In short, moving JS to the footer can break dependencies.
Using “defer” Instead
Just as the ability of browsers to simultaneously download lots of files rendered the practice of combining them obsolete, the “defer” and to a lesser extent, the “async” attribute have rendered obsolete, the practice of placing external JS files in the footer.
Page Optimization is Specific to Each Website
Just remember that there is no single or easy solution for fast page speeds. Often there need to be specific adjustments that are unique to your site, as well as tradeoffs that you need to decide how to live with.
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!
Leave a Reply