Support » Plugin: Autoptimize » Separate CDN Base URL for JS and CSS

Viewing 15 replies - 1 through 15 (of 32 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    hmmm … a question first; does statically honor the directory structure the JS or CSS is found in? e.g. https://cdn.statically.io/js/example.com/wp-content/plugins/autoptimize/classes/external/js/lazysizes.min.js ?

    Thread Starter woorooo

    (@woorooo)

    Yes, it should work exactly like that.

    Thread Starter woorooo

    (@woorooo)

    They have their own plugin for wordpress which handles this automatically, but with their plugin enabled there is no way to benefit from AO optimizations in that case. They serve JS and CSS as they are. They only way to make it work with AO is via AO settings apparently.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, something like this code snippet might help;

    
    add_filter( 'autoptimize_filter_cssjs_multidomain', function(){ 
    return array( 'https://cdn.statically.io/js/example.com', 'https://cdn.statically.io/css/example.com' ); 
    } );
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Did that code snippet help woorooo ?

    Thread Starter woorooo

    (@woorooo)

    No, as far as I remember it didn’t, however I solved the problem the other way. I inlined all CSS, so that AO would output only aggregated js file.

    However again, after testing properly with Pagespeed Insights from Google, I decided to serve js from my domain. This combination of inlined CSS and JS without CDN gave best performance. So I serve only images via Statically CDN since then.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    yeah, loading critical resources from a different domain (often) does not help performance (due to the overhead of setting up the connection and encryption).

    happy you found a sweet spot in your configuration 🙂
    frank

    Thread Starter woorooo

    (@woorooo)

    Hi @optimizingmatters

    I’ve made a few changes on the website and would like to test again serving JS and CSS from separate URLs with the snippet you provided

    add_filter( 'autoptimize_filter_cssjs_multidomain', function(){ 
    return array( 'https://cdn.statically.io/js/example.com', 'https://cdn.statically.io/css/example.com' ); 
    } );

    Unfortunately I cannot make it work. I’ve left CDN Base field in the AO settings blank, I’ve inserted the snippet via Snippet Plugin and changed the urls to my domain. But still nothing. Am I doing something wrong?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    very hard to say I’m afraid based only that info. forgetting about the code snippet for a second: what happens if you -with aggregate JS on- set the CDN to https://cdn.statically.io/js/example.com ? does the JS get aggregated?

    Thread Starter woorooo

    (@woorooo)

    Yes, it works as it should in this case. Aggregated and excluded js files are served via that URL

    • This reply was modified 2 years, 7 months ago by woorooo.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    and the other way around, if you enter https://cdn.statically.io/css/example.com does the CSS get aggregated/ optimized?

    Thread Starter woorooo

    (@woorooo)

    Yes it does.

    When only one of the CDN urls is used, everything works as expected.

    • This reply was modified 2 years, 7 months ago by woorooo.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, maybe try to keep one of those two set as CDN and then activate the code snippet?

    Thread Starter woorooo

    (@woorooo)

    Yep, I’ve tried different combination of that as well. The snippet just doesn’t seem to be doing anything. Can there be some mistake in the code itself?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    try adding error-logging to the code snippet and then check the PHP error-log to see if the logged string is there in which case we at least know if the snippet gets triggered?

    
    add_filter( 'autoptimize_filter_cssjs_multidomain', function(){ 
        error_log( 'snippet triggered' );
        return array( 'https://cdn.statically.io/js/example.com', 'https://cdn.statically.io/css/example.com' ); 
    } );
Viewing 15 replies - 1 through 15 (of 32 total)
  • The topic ‘Separate CDN Base URL for JS and CSS’ is closed to new replies.