WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
CDN Troubles with dynamic css (4 posts)

  1. bheadrick
    Member
    Posted 1 year ago #

    A number of plugins and themes have some method where they "compile" css through some PHP file - often using a query string - Obviously, since this isn't a static file, it's not something a CDN could mirror as it's referenced. Is there perhaps a way to at least cache these files via page caching, and perhaps even allow the CDN to, then, mirror them?

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. mikeotgaar
    Member
    Posted 1 year ago #

    One way to achieve this - not the one you wanted - but it works
    (I hate these dynamic CSS files. Really unnecessary - who changes css daily (Plugin authors take note - just one pet gripe)
    The dynamic file usually does get cached, then the plugin using dynamic css refreshes the css file, adds a new time based id - usually to the end of the file name, and the next time a page get's cached it uses the new file name - which isn't in the cache... Arrgggh)

    My Workaround
    My workaround is simply to save a static copy of the file - and hack the plugin to remove the dynamic generation and use this static file (braking the Golden Rule - don't modify) - Then add a note in the plugin style.css (Description: )to remind me in plugin list the plugin is modded and I need to re-mod when updating), and a link to a note reminding me what I did.

    But maybe someone has the htaccess instruction to regenerate the css cache and minify, then upload it to the CDN - or a plugin to add this to W3

  3. bheadrick
    Member
    Posted 1 year ago #

    well, yes, that certainly does work, but it's a pain...

    I have figured out how to at least get the htaccess rules to work so the dynamic css has a fancy url. Here's the example I used for the jquery mega menu plugin - this htaccess file goes on the same level as the skin.php file:

    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /wp-content/plugins/jquery-mega-menu

    RewriteRule ^([^/]+)-([^/]+)\.css$ skin.php?widget_id=$1&skin=$2 [NC]
    </ifmodule>

    Now, the trick is to replace the reference to that file to use the fancy url.
    There's probably a way to do it without hacking up the plugin, but since this particular plugin isn't using any hooks to enqueue the css, I'm just going to modify the plugin to make it use the fancy url.

    It's currently working and the file got picked up by the cdn! woohoo!

    I wonder how hard it would be to package something like this into a separate plugin to "fix" dynamic css files like this.

  4. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    If I understand correctly, you can minify that file with W3TC and specify an interval when the cache will be rebuilt, default is 1 day. From there you can do nothing differently and still have a dynamic file in use.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic