Title: Loading scripts and styles
Last modified: February 20, 2022

---

# Loading scripts and styles

 *  [rsmith4321](https://wordpress.org/support/users/rsmith4321/)
 * (@rsmith4321)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/loading-scripts-and-styles/)
 * Your plugin sounds perfect for what I need, however, I only need the calendar
   on one page and it loads scripts and styles for every page on the whole site.
   I hate when plugins do that. Can you update this to only loads the CSS and js
   on the page the calendar is being used on?

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

 *  Plugin Author [Room 34 Creative Services, LLC](https://wordpress.org/support/users/room34/)
 * (@room34)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/loading-scripts-and-styles/#post-15384617)
 * I understand your concern about this; unfortunately with the default setup of
   WordPress, there’s not a way to know whether or not a shortcode appears on the
   page at the point where scripts and styles are loaded.
 * Client-side caching helps avoid having to actually transfer the data on each 
   page load. There is a minimal impact from the browser loading these assets, but
   the scripts are coded so that they don’t do anything unless the elements of the
   calendar are on the page.
 * All of that said… there _are_ some ways around this. There hasn’t been much demand
   for this so I haven’t given it a lot of attention, but I will have a look.
 * In the meantime, you could write some conditional logic on your own site to dequeue
   the scripts except on the page you want them to appear on. It would be something
   like this:
 *     ```
       add_action('wp_enqueue_scripts', function() {
           if (1 == 2) { // Replace with your conditional logic
               global $R34ICS;
               wp_dequeue_script(array($R34ICS, 'enqueue_scripts'));
           }
       }, 99);
       ```
   
 * (This _should_ work; I haven’t actually tested it.)
 *  Plugin Author [Room 34 Creative Services, LLC](https://wordpress.org/support/users/room34/)
 * (@room34)
 * [4 years, 3 months ago](https://wordpress.org/support/topic/loading-scripts-and-styles/#post-15400609)
 * Still mulling this issue over. I found a nice blog post that illustrates the 
   exact set of options I had considered, and the associated issues with each:
 * [austingil.com/conditional-scripts-styles-for-wordpress-shortcodes](https://austingil.com/conditional-scripts-styles-for-wordpress-shortcodes/)
 * At this point I still don’t have a definitive solution although I am inclined
   to experiment with option #1. The problem is, there will _definitely_ be [“FOUC”](https://en.wikipedia.org/wiki/Flash_of_unstyled_content)
   with this approach and ICS Calendar.
 * For now, suffice to say, you can see why I have so far chosen to “kick the can
   down the road” on this problem.
 * (By the way, the code example I gave in my initial reply is, effectively, the
   same thing as “Option #3” in the blog post.)
    -  This reply was modified 4 years, 3 months ago by [Room 34 Creative Services, LLC](https://wordpress.org/support/users/room34/).

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

The topic ‘Loading scripts and styles’ is closed to new replies.

 * ![](https://ps.w.org/ics-calendar/assets/icon.svg?rev=3427980)
 * [ICS Calendar](https://wordpress.org/plugins/ics-calendar/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ics-calendar/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ics-calendar/)
 * [Active Topics](https://wordpress.org/support/plugin/ics-calendar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ics-calendar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ics-calendar/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Room 34 Creative Services, LLC](https://wordpress.org/support/users/room34/)
 * Last activity: [4 years, 3 months ago](https://wordpress.org/support/topic/loading-scripts-and-styles/#post-15400609)
 * Status: not resolved