Support » Plugin: Autoptimize » No CSS Aggregation With Custom WP_CONTENT_URL

  • Resolved Andrew

    (@andrewspear)


    I’ve found that if I define a custom (relative) value for WP_CONTENT_URL then the CSS files are not aggregated.

    For example if I add this to wp-config.php:

    define('WP_CONTENT_URL', '/wp-content');

    I get a whole bunch of CSS files which seem to be bypassing Autoptimize:

    But if I remove the WP_CONTENT_URL definition completely the files are aggregated as expected:

    The two files not aggregated in this screenshot are marked as exclusions in Autoptimize so the result shown is what I would expect.

    Is there any way to get Auotptimize working with relative content URLs?

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

    (@optimizingmatters)

    OK, I *think* I fixed it in AO29 Beta, can you download & install that instead of 2.8.4?

    You still might have to set another define though because AO will not be able to set AUTOPTIMIZE_WP_CONTENT_URL itself if WP_CONTENT_URL does not contain the domain, e.g.;

    define('AUTOPTIMIZE_WP_CONTENT_URL', 'http://localhost/wordpress/wp-content');

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    hmmm, the fix might not be 100% yet, some unit tests failed, will look into this again later today.

    Thread Starter Andrew

    (@andrewspear)

    @optimizingmatters Thanks for looking into this, please keep me posted.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, took me some time to understand, but unit tests were failing because they were not 100% correct (details; some tests use custom contants which switched the test to sub-folder installs in which case absolute paths in the unit tests caused the JS/ CSS to be out of the WordPress root folder which caused the getpath test with custom constants to fail, so now the getpath test differentiates between “custom contants” and non-cc).

    So tests fixed, all is ready for you to test now Andrew 🙂

    Thread Starter Andrew

    (@andrewspear)

    Thanks @optimizingmatters

    Is the Beta link above still the correct URL to use? It installs version 2.9.0-beta-2 does that have the latest changes? Unfortunately I don’t see any difference with this version (I installed the new version and disabled the original one).

    With define('WP_CONTENT_URL', '/wp-content'); set in wp-config.php I get no AO:

    If I remove WP_CONTENT_URL I get the expected result:

    If I remove WP_CONTENT_URL and also disable aggregation it also works as expected:

    It seems that whenever I set WP_CONTENT_URL AO doesn’t kick in 🤔

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    ah, but as per my previous comment you should also set AUTOPTIMIZE_WP_CONTENT_URL, did you try that?

    Thread Starter Andrew

    (@andrewspear)

    Ah yes, thanks @optimizingmatters, it’s working as expected with these two lines:

    define('WP_CONTENT_URL', '/wp-content');
    define('AUTOPTIMIZE_WP_CONTENT_URL', 'https://' . $_SERVER['SERVER_NAME'] . WP_CONTENT_URL);
    

    🥳

    • This reply was modified 1 month ago by Andrew.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Super! 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.