Mobile Optimization: avoid loading css and js on every page load
Hi, I have seen the “ressource hog” post to late, but using is_frontpage is not a solution for me because my sliders are on several pages.
I would like to suggest a more flexible solution – you could easily help us with this by adding only four lines of code to your plugin and bring a huge benefit to advanced users:
in meteor-slides-plugin.php on top add
defined('METEOR_SLIDES_LOAD_CSS') or define('METEOR_SLIDES_LOAD_CSS', true); defined('METEOR_SLIDES_LOAD_JS') or define('METEOR_SLIDES_LOAD_JS', true);
then before the call of wp_enqueue_script on line 218 add
if ( METEOR_SLIDES_LOAD_CSS )
and before wp_print_scripts on line 244 add
if ( METEOR_SLIDES_LOAD_JS )
This would enable users to add this
define('METEOR_SLIDES_LOAD_CSS', false); define('METEOR_SLIDES_LOAD_JS', false);
to wp-config.php and then e.g. do this in a template page where the slides are actually used:
This can of course be used in other places and ways, however the great effect is that if you know, where your slides are – and usually you do not have them on every page – you can load css and js for your plugin only where it is needed and save some requests on all the other pages!
Would you mind adding these four lines of code to your plugin?
I tested it and see no problems – it is just a “hidden gem” for speed-junkies 🙂
I adapted this idea from the CF7 contact form plugin author, who finally gave us a solution for not loading the CF7 js + css on every F* page when you have just one contact form… you can check this here:
Meanwhile there seem to be a few options for doing conditional js and css loading (e.g. ), but I think the very quick solution above could help a lot until you feel like figuring out something else.
Thanks for your attention!
- The topic ‘Mobile Optimization: avoid loading css and js on every page load’ is closed to new replies.