Support » Plugin: Jetpack by WordPress.com » Serve JS Locally?

  • Resolved Hyflex

    (@hyflex)


    Hi,

    I’m wanting to serve the JS locally from my server as all of my JS is served via a CNAME CDN that supports HTTP/2 with ALPN and ultimately would be faster as there would be less lookups and I can combine with my other javascript files and a few other things.

    Is there a toggle in Jetpack to allow me to switch to a “serve locally”? If not then that’s my request & suggestion.

    I know I can do it manually by using wp_dequeue_script and then add my own, but that’s not as efficient as a toggle directly in jetpack.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Is there a toggle in Jetpack to allow me to switch to a “serve locally”? If not then that’s my request & suggestion.

    There is no such toggle, but you can rest assured: most of the resources loaded by Jetpack are already served locally. A few resources are served from our own CDN, but all those resources are served via HTTP/2 so you don’t have to worry about optimizing them.

    I hope this clarifies things a bit.

    Hi Jeremy,

    I understand your thoughts on this and for most people it would be faster, however in my case and a growing amount of other users it’s not faster.

    I’ve tested this thoroughly and it is faster for me to serve the files from my server even with my CDN being disabled.

    I ran a few tests and compared several options and got the following results (over 100 loads):

    Jetpack Served Externally = 2.13
    Jetpack Served Externally with CDN = 2.07
    Jetpack Served Externally with AutoOptimize = 2.08
    Jetpack Served Externally with AutoOptimize & CDN = 1.93

    Jetpack Served Internally = 1.95
    Jetpack Served Internally with CDN = 1.84
    Jetpack Served Internally with AutoOptimize = 1.86
    Jetpack Served Internally with AutoOptimize & CDN = 1.67

    My server already has HTTP/2, ALPN setup so with everything setup internally/locally it is straight away faster and then when I add AutoOptimizie and enable my CDN it ends up 3 tenths faster.

    Even if you sort of hide the option with something like the code below to make sure people don’t use the option normally (because for most users it would be better to not enable the feature)

    add_filter(‘jetpack_servejslocally’,’servejslocally_trigger’,10,0);
    function servejslocally_trigger(){
    return true;
    }

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Thanks for the extra details.

    Are there specific external Jetpack resources that you use on your site and found were slowing things down?

    Hi Jeremy,

    Individually I found that pretty much every resource was slower being served from Jetpack’s CDN over my own server (for my location) or my CDN (multiple locations)

    Is there a reason you’re against adding an option to serve locally?

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Is there a reason you’re against adding an option to serve locally?

    I’m not particularly against it; in fact and as you mentioned, it’s already possible to do that manually by dequeuing the files and enqueuing a local copy instead.

    However, if resources loaded from Jetpack’s CDN are slower than the ones loaded on your own server then that means we have room for improvement, and I’d like to know where to start investigating 🙂

    Which Jetpack modules do you use on your site right now? How many external resources are causing issues?
    As I mentioned earlier, most js files used in Jetpack are hosted locally, except for a few: our Stats tracking code comes to mind, as well as the library used to handle images on HiDPi / Retina devices. Gravatar and VideoPress resources are also loaded remotely. I believe that’s about all the resources that should be loaded remotely on the frontend of your site. Am I forgetting some? Which ones are slower than you’d like on your site?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Serve JS Locally?’ is closed to new replies.