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

Viewing 15 replies - 16 through 30 (of 32 total)
  • Thread Starter woorooo

    (@woorooo)

    Just to confirm, it should show up in the error log which is enabled via wp-config wp_debug true?
    If so, nothing is showing up in the log.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    wp_debug normally outputs on the page, what we’re looking for is a PHP error logfile on the server filesystem, so likely not the same thing. maybe ask your host?

    Thread Starter woorooo

    (@woorooo)

    I’ve checked all the logs that my server outputs:
    nginx_wordpress.error.log showed lots of this type of errors coming from Autoptimize:

    2021/08/29 19:24:41 [error] 28564#28564: *494347 open() "/public_html/wp-content/cache/autoptimize/css/autoptimize_7bc92c985daae96af0ff7a8fd94a8905.css" failed (2: No such file or directory), client: 187.246.170.90, server: XXXXX.cloudwaysapps.com, request: "GET /wp-content/cache/autoptimize/css/autoptimize_7bc92c985daae96af0ff7a8fd94a8905.css HTTP/2.0", host: "www.mywebsite.com"

    apache_wordpress.error.log nothing there that relates to the above mentioned string of Autoptimize

    Are these the logs you meant? Because there are no other error log files from the server on my end, only access logs.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    It looks like it would be nginx_wordpress.error.log then, no occurrences of the snippet triggered log in there? :-/

    Thread Starter woorooo

    (@woorooo)

    None, I’ve doubled checked everything and tested with and without cdn base url option inserted once more. What does this mean?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    so you’re using the code snippets plugin, right? can you share a screenshot of the code snippet screen with the snippet (about to hit the sack now, but I’ll follow up tomorrow)?

    Thread Starter woorooo

    (@woorooo)

    Sure, here is the screenshot https://ibb.co/B62kLsk.

    Thank you for taking time to look into it and sorry for bothering you on Sundays, just realized it 🙁

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    re. Sundays: no worries, AO started out as and still is a hobby first and foremost and hobbies don’t know about workdays or weekends 😉

    But here we are, Monday morning, AO 2.9.2 was just released, I’m nicely coffeed up and ready to get to the bottom of this, so time permitting I’ll play with statically.io myself on one of my blogs and get back to you with -hopefully- a solution.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, have a solution that works on one of my sites;
    1. disable CSS & JS CDN in statically settings (AO will put it on the CDN)
    2. set CDN url in AO to https://cdn.statically.io/css/yourdomain.com
    3. and then use this code snippet to switch to the JS CDN URL for JS-files:

    add_filter( 'autoptimize_filter_base_replace_cdn', function( $url_in ) {
    	if ( autoptimizeUtils::str_ends_in( $url_in, 'js' ) ) {
    		$url_in = str_replace( 'https://cdn.statically.io/css/', 'https://cdn.statically.io/js/', $url_in );
    	}
    	return $url_in;
    });
    Thread Starter woorooo

    (@woorooo)

    Wow, this one worked 🙂 Thank you so much!

    There is only one js file that is still served from my domain:
    /wp-content/plugins/geodirectory/assets/js/geodir-map.min.js

    Can you think of any possible reasons why this one is not being picked up by AO?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    I assume geodirectory uses one of the many ways (API, attribute in the tag, tweaking settings, ..) to exclude their JS from being optimized? 🙂

    Thread Starter woorooo

    (@woorooo)

    Got it, most likely it does 🙂

    Just one more question, I’ve also noticed that local font files are not served via cdn, though they are triggered by aggregated AO css file. Are they supposed to be served via AO CDN settings as well or it’s better to leave them like that?

    Thanks.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    by default fonts are not served through a CDN because that can cause CORS-issues with the fonts not being loaded at all. if you insist, you can try with the filter below though (there’s always a filter 😉 );

    add_filter( 'autoptimize_filter_css_fonts_cdn', '__return_true' );

    Thread Starter woorooo

    (@woorooo)

    For some reason this filter doesn’t work on my side 🙁 I’ve tried disabling the previous snippet to see if it can cause problems for it. But no, the fonts are still loaded bypassing cdn.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Yeah, fonts can be a drag 🙂 Maybe clearing AO’s cache helps, but if not I’m out of ideas I’m afraid :-/

Viewing 15 replies - 16 through 30 (of 32 total)
  • You must be logged in to reply to this topic.