• Resolved JasperPress

    (@jasperpress)


    I was wondering if it is possible to only load the plugin scripts when the Instagram Feed is inserted on the page.
    The way it works now is that the scripts and stylesheets are loaded on all pages and posts, even if there is no instance of the IG feed present. This means extra loading time that can be avoided.

    Is there a way to prevent the scripts/stylesheets from loading when they are not needed?

    https://ww.wp.xz.cn/plugins/instagram-feed/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author smashballoon

    (@smashballoon)

    Hey Jasper,

    As the plugin uses a shortcode to load the feed then it’s difficult to do this, as when loading the header of your site it doesn’t know yet whether the [instagram-feed] shortcode is going to be in the content of that page. The good news is that as web browsers cache CSS and JavaScript files then there isn’t any additional requests or loading time when the visitor goes from page to page.

    If you really wanted to only load the plugin files on certain pages then you could dequeue the plugin CSS and JavaScript files in your theme’s functions.php file and then add a conditional in your header and footer file which only includes them on certain pages. Let me know whether that makes sense.

    John

    Thread Starter JasperPress

    (@jasperpress)

    Hi John,

    Thanks for the speedy response.
    I totally get what you’re saying and you have a good point.
    Since the feed is shown on the homepage the script is already cached by most of the visitors and it would seem to much of a hassle to dequeue it and conditionally add it again.

    Cheers!
    Jasper

    Plugin Author smashballoon

    (@smashballoon)

    No problem, just let me know if you have any other questions at all and I’d be happy to help!

    Also, no obligation of course, but if you like the plugin and feel like leaving a super-quick review then we always really appreciate it 🙂

    John

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

The topic ‘Only load scripts weh needed’ is closed to new replies.