How to defer parsing of JavaScript

The simplest and most effective way to defer parsing of JS is by using CloudFlare Rocket Loader. However, if for some reason you're unable to use it, here's some other ways to handle this. Please keep in mind that optimizing JS can be tricky. While on some sites it's a walk in the park, on others it can be a tedious trial and error process. Let the common sense guide you, please remember that the endgame is high speed, not high scores.

You can combine and defer JS using Autoptimize. Under Settings, open Advanced, check Optimize JS and make sure Force in <head> is not checked. Save and clear all caches and check your site. If something is broken, go back and add Try-catch wrapping. Save and clear all caches and check again. If something is broken, try excluding that script by adding it in the Exclude scripts from Autoptimize box. Save, clear, check. And so on. If nothing's working, use Force in <head>. Your JS will be combined but not deferred. Don't let it upset you, remember - you're after speed, not scores and there's always a trade-off between functionality and speed.

Please keep in mind that you should only use one method for optimizing JS. If you're using Rocket Loader, then don't use Autoptimize or another plugin for the same purpose and vice versa. Also, when you're working on JS it's best to keep Minify JS under Speed on CloudFlare unchecked, at least in the beginning to prevent JS from breaking.

We use cookies for your best experience.