Support » Plugin: The Events Calendar » [Plugin: The Events Calendar] Prevent Events CSS and JS on pages its not used?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hey there pers0n, thanks for reaching out and for the heads up. Can you give me an example of this that I can share with the devs, so they can offer up some feedback and possibly get this resolved for a future release if it’s cause for concern? Thanks!

    Thread Starter pers0n

    (@pers0n)

    Every page is loading the following:

    <link rel=’stylesheet’ id=’tribe-events-calendar-style-css’ href=’http://example.org/wp-content/plugins/the-events-calendar/resources/events.css?ver=3.3.2&#8242; type=’text/css’ media=’all’ />
    <script type=’text/javascript’ src=’http://example.org/wp-content/plugins/the-events-calendar/resources/jquery.pjax.js?ver=3.3.2′></script&gt;
    <script type=’text/javascript’ src=’http://example.org/wp-content/plugins/the-events-calendar/resources/events.js?ver=3.3.2′></script&gt;

    I dont need the JS and CSS files loading on my homepage. Really they should be loaded only when the calendar is being used on those special templates.

    Hi there pers0n. I apologize that it took us some time to get you a response here; we generally hit the forum once a week and that’s been cut down due to the holiday weekend and some corresponding team vacations.

    Is this still a concern? If you’re still using the plugin and haven’t given up on us yet, I can get a dev to check on this for you in a timely fashion. Let me know. Sorry again for the delay.

    Thread Starter pers0n

    (@pers0n)

    I would really like to limit this to pages that need it only. I always try to make lightweight sites. Thanks.

    One thing I’d suggest, if you’re still aiming to do this, would be to update to 3.4 and see if the issue persists (when running Events 2.0.7). Let me know how that goes and we’ll do what we can to assist.

    I don’t think is a question of updating WordPress.

    It isn’t an issue, normally all plugins load the css and the js throughout the whole website and I hate this.

    For speed purposes and performance it would be nice to only load the calendar’s JS and CSS code when needed.

    To overcome this issue i made a simple fix, add the following to your theme’s functions.php and change the value in !is_page for the value of the page where your calendar is located, or if you dont know the id use the slug ‘Events’.

    The script deregisters js and css code on all pages exept the one you put in the !is_page(‘Events’). this means that it will only be loaded in Events page and not all other pages.

    // DEREGISTER JAVASCRIPT EVENTS
    function decalendarjs() {
    if ( !is_page('1176') ) { 
    
    wp_deregister_script('tribe-events-pjax');
    wp_deregister_script('tribe-events-calendar-script');
    
    	}
    }
    add_action( 'wp_print_scripts', 'decalendarjs'); // now just run the function
    
    // DEREGISTER JAVASCRIPT EVENTS
    function decalendarcss() {
    if ( !is_page('1176') ) { 
    
    wp_deregister_style('tribe-events-calendar-style');
    
    	}
    }
    add_action( 'wp_print_styles', 'decalendarcss'); // now just run the function

    The issue now is that, they will be loaded in the calendar page but when you click on an event, as it has different ID they will not be loaded, now what do we do

    I found the solution

    REPLACE

    if ( !is_page('1176') )

    WITH

    if ( get_post_type() !== 'tribe_events' )

    Hah – that raises a good question. This has gone a bit outside my area of expertise, but I’ve asked Jonah from our dev team to take a look in case he has any ideas. No guarantees but is worth a shot. Stay tuned.

    NICE! You’d posted this even before I sent that last message, so ignore it. I’ll assume your comment on the other thread (http://wordpress.org/support/topic/plugin-the-events-calendar-load-js-and-css-only-in-calendar-pages?replies=1) is accurate based on this, though let me know if I’m wrong.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Plugin: The Events Calendar] Prevent Events CSS and JS on pages its not used?’ is closed to new replies.