Page Speed

Speedup WordPress By Dequeue Unused Scripts

Core Web Vitals is coming. Users prefer faster pages, so on search, faster pages (that are relevant) will be returned first. Recently I installed “The Events Calendar” for WordPress. I found it was loading a large amount of Javascript and CSS on ever page. But I only use it on /events (and its own post types). What do to to speedup wordpress?

In my Quest for Web Site Performance Perfection, I found these enqueues scripts, no matter whether you minifed or preloaded, were causing a lot of excess CPU and parse time. An infinitely fast network cannot help. Its probably also using your battery up. So, let’s dig in.

First, we have to track them all down. To do this I added an echo statement to where they were enqueued. There may be a more elegant way by reading the fine documentation, but, I was in a hurry and this worked.

Once done, I added this below function to my theme functions. What it does is “if this page is a tribe_event or /events then allow else dequeue”. This will speedup wordpress: less things sent to user.

Install, load, done. Now I have 42 less scripts/js enqueued, and this means more CPU for parsing other things, and, more battery for you the reader.

You can test your changes with the Chrome Lighthouse, or Efficiency is in everyones interest, so save a bit, save a watt, speedup wordpress.

add_action( 'wp_enqueue_scripts', function() {

    global $wp;

    $post_type = get_post_type();
    if ($post_type != "tribe_events" && $wp->request != "/events/") {

        $junk_script = [

        $junk_style = [

}, 99);