Title: Load FancyBox Code only when Needed
Last modified: August 21, 2016

---

# Load FancyBox Code only when Needed

 *  Resolved [fhaynes3](https://wordpress.org/support/users/fhaynes3/)
 * (@fhaynes3)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load-fancybox-code-only-when-needed/)
 * What can be done so that FancyBox code is only included in the page if it is 
   used?
 * [https://wordpress.org/plugins/easy-fancybox/](https://wordpress.org/plugins/easy-fancybox/)

Viewing 1 replies (of 1 total)

 *  [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/load-fancybox-code-only-when-needed/#post-5124947)
 * Sadly, there is no solid way for the plugin to ‘detect’ if the script is going
   to be needed before content is rendered by WordPress. If only all images where
   embedded with a shortcode like galleries then there would be a trigger to hook
   on to… The alternative is filtering each post content on every request with a
   complicated regex search to find any possible media links that might need script
   action. This method is more ‘expensive’ (in terms of server load and response
   times) than simply including the script on all pages.
 * Just disable all FancyBox options that you do NOT need to make sure you have 
   the leanest script version possible. Then, if you want to go further, I can recommend
   installing W3TC for caching and activate script minification + concatination.
   But test your site as an anonymous visitor to make sure no script action is broken
   after activating these advanced features!

Viewing 1 replies (of 1 total)

The topic ‘Load FancyBox Code only when Needed’ is closed to new replies.

 * ![](https://ps.w.org/easy-fancybox/assets/icon-256x256.png?rev=3188201)
 * [Firelight Lightbox](https://wordpress.org/plugins/easy-fancybox/)
 * [Support Threads](https://wordpress.org/support/plugin/easy-fancybox/)
 * [Active Topics](https://wordpress.org/support/plugin/easy-fancybox/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/easy-fancybox/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/easy-fancybox/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/load-fancybox-code-only-when-needed/#post-5124947)
 * Status: resolved