Title: Loading JS when not needed
Last modified: August 22, 2016

---

# Loading JS when not needed

 *  Resolved [Squazz](https://wordpress.org/support/users/squazz/)
 * (@squazz)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/loading-js-when-not-needed/)
 * I have just run a couple of speed tets om my site, and it seems that JS files
   for Meteor Slides are fetched even when they aren’t needed.
 * We are talking about 4 requests with a combined weight at about 19.5Kb:
    meteor-
   slides/js/jquery.cycle.all.js?ver=4.0.1 meteor-slides/js/jquery.metadata.v2.js?
   ver=4.0.1 meteor-slides/js/jquery.touchwipe.1.1.1.js?ver=4.0.1 meteor-slides/
   js/slideshow.js?ver=4.0.1
 * In this post for two years ago another person wrote about this too: [https://wordpress.org/support/topic/plugin-meteor-slides-request-load-js-only-when-needed](https://wordpress.org/support/topic/plugin-meteor-slides-request-load-js-only-when-needed)
 * Can it be true that this havn’t been adressed yet?
 * [https://wordpress.org/plugins/meteor-slides/](https://wordpress.org/plugins/meteor-slides/)
 * Example page with the problem: [https://www.musalaha.org/about-us/who-we-are/](https://www.musalaha.org/about-us/who-we-are/)
 * Sidenote: Can it be true that Meteor Slides aren’t serving minimized version 
   of the JS?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Josh Leuze](https://wordpress.org/support/users/jleuze/)
 * (@jleuze)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/loading-js-when-not-needed/#post-5547524)
 * Hey Squazz, that’s right the slideshow scripts are currently loaded on every 
   page. I’ve got some performance improvements planned for the next version of 
   Meteor Slides, including loading those scripts conditionally, combining and compressing
   the scripts, and also reducing the number of images used for the slideshow navigation.
 * In the mean time there are steps you can take to speed it up for your own use.
   Like if you only have a slideshow in the homepage, you can [load the scripts on just the homepage](https://wordpress.org/support/topic/meteor-slides-load-cssscripts-only-on-home-page?replies=2).
   Or you could disable the scripts completely, and add these to your theme so that
   you can get the most control over them.
 * If performance is a major concern you could remove all the scripts and stylesheets
   from your plugins and load just a single compressed script and stylesheet from
   your theme. If you aren’t already doing so, I have found that the biggest speed
   boost you can get with a slideshow is from using an compressor in the slide images.
   Taking 160k images and crunching them down to 80k can have a way bigger impact
   than a 20k script. Or simply switching from 10 slides to 5 slides can cut the
   load time in half!
 *  Thread Starter [Squazz](https://wordpress.org/support/users/squazz/)
 * (@squazz)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/loading-js-when-not-needed/#post-5547526)
 * Thank you so much for your reply. This must be one of the best replies I have
   gotten on a plugin support so far! 😀
 * I am so glad that you are aware of the problem, and is focussing on fixing it.
   Speed is (at least for me) almost everything, as long the job still gets done.
   You are probably aware of how to do this properly, but I just stubled upon this
   post the other day: [http://scribu.net/wordpress/optimal-script-loading.html](http://scribu.net/wordpress/optimal-script-loading.html),
   and I plan on doing something like this myself.
 * I will try to look at just loading the scripts on my homepage. Or as you suggest,
   disable them and then with my own code control when they are loaded.
 * About using 5 images instead of 10, and compressing images, these two things 
   is something I would like to dwell a little more with.
 * From my perspective, we should not load all of the images in the same batch. 
   We should lazy load them. It should not matter if we have 5, 10 or 20 images.
   We should only load the first image to start with, then the next one when needed.
   Maybe, load the first two and then wait. One of the reasons is that I want as
   fast a initial pageload as possible. Secondly, I see that many of my users are
   only seeing the first, maybe the second image. When this is the case, it seems
   like a waste to load 5 images if only two of them is being shown to the user.
 * About compression, then there is no doubt that you are right about that the images
   is the heavy load. But you can’t do anything about our images (at least, I don’t
   want you to 😉 ). What you can do instead is ensure that your plugin is as light
   as a feather 😛
    I myself, is working on some way to use pictureFill 2 on all
   of my sites. As well as leveraging Photon from JetPack. These two tings combines
   seems for me to be the way to go if we want to have high quality images that 
   loads fast.
 * Once again, thanks for the reply.
    Keep up the good work, I’m looking forward
   to the update 🙂
 *  Plugin Author [Josh Leuze](https://wordpress.org/support/users/jleuze/)
 * (@jleuze)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/loading-js-when-not-needed/#post-5547528)
 * You’re welcome Squazz, I’ve got a few ideas for optimizing the scripts, but I’m
   still doing some research on the best approach to take.
 * I haven’t tried PictureFill 2 or Photon yet but I should really look into those!
 *  Thread Starter [Squazz](https://wordpress.org/support/users/squazz/)
 * (@squazz)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/loading-js-when-not-needed/#post-5547549)
 * I may have found a solution for how you can load the JS & CSS files only when
   needed. But I’m sure you will like it.
 * Originally i just searched for a shortcode, and then added the scripts and CSS
   if the shorttag was found. But this gave some problems with my specific setup
   as I’m using the PHP version directly in a template. Futhermore I’m quite sure
   it won’t work with widgets?
 * In short, what I did was to just move the loading of JS & CSS to meteor-slideshow.
   php, and then edit the path to something like this:
 *     ```
       plugins_url( '/meteor-slides/js/jquery.cycle.all.js')
       ```
   
 * It works, but I’m not sure it wil ALWAYS work. Futhermore it kinda moved code
   to somewhere where it doesn’t belong. Even though I feel it kinda belongs there
   anyway 😉
 * If this is something you wanna chat about, discuss different approaches, I’m 
   willing to do that. I’m rather interested in it myself. But, if you want to do
   that is there then somewhere we can chat about it instead of using the WordPress
   Support page?
 *  Plugin Author [Josh Leuze](https://wordpress.org/support/users/jleuze/)
 * (@jleuze)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/loading-js-when-not-needed/#post-5547556)
 * That’s an interesting idea! I know there were a few different techniques for 
   checking if scripts should be loaded, but at the time they were more resource
   intensive than just loading the scripts on every page. I haven’t researched recently
   to see if there is a better way now though.
 * Feel free to get in touch with me [on my website](http://jleuze.com/contact/)
   if you’d like to.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Loading JS when not needed’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/meteor-slides_0f131a.svg)
 * [Meteor Slides](https://wordpress.org/plugins/meteor-slides/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/meteor-slides/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/meteor-slides/)
 * [Active Topics](https://wordpress.org/support/plugin/meteor-slides/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/meteor-slides/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/meteor-slides/reviews/)

## Tags

 * [js](https://wordpress.org/support/topic-tag/js/)

 * 5 replies
 * 2 participants
 * Last reply from: [Josh Leuze](https://wordpress.org/support/users/jleuze/)
 * Last activity: [11 years, 5 months ago](https://wordpress.org/support/topic/loading-js-when-not-needed/#post-5547556)
 * Status: resolved