WordPress.org

Ready to get started?Download WordPress

Forums

WP Super Cache
[resolved] - adding max-age for images/css (6 posts)

  1. damaha
    Member
    Posted 2 years ago #

    Hi,

    I use the mod-rewrite option in WP Super Cache, it seems to work.

    As the plugin does not add expiry dates or max-age for images or css, I modified the .htaccess file in the cache folder (wp-content/cache/) manually and added max-ages for images and css. (I cannot use the expiry module with my virtual server, so I cannot add expiry dates.)

    I added the following code to the .htaccess file in the cache folder:

    # BEGIN Cache-Control Headers
    <ifmodule mod_headers.c>
      <filesmatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$">
            Header set Cache-Control "max-age=86400"
      </filesmatch>
      <filesmatch "\.(css|pdf)$">
            Header set Cache-Control "max-age=86400"
      </filesmatch>
      <filesmatch "\.(js)$">
            Header set Cache-Control "max-age=86400, private"
      </filesmatch>
    </ifmodule>

    The whole file now looks like this:
    http://pastebin.com/B4WGnTjM

    But when I check the browser caching of static assets, I still get the message: No max-age or expires for the images and the css file.

    Can anyone please help?
    Many thanks in advance.

  2. damaha
    Member
    Posted 2 years ago #

    You can look at my WordPress-site under http://www.trustablegold.de.

  3. Donncha O Caoimh
    Member
    Plugin Author

    Posted 2 years ago #

    Add that code to your main .htaccess file as images and css aren't cached!

  4. damaha
    Member
    Posted 2 years ago #

    Great, it seems to work now.
    Thanks a lot!!

  5. tonyzeoli
    Member
    Posted 2 years ago #

    I just want to confirm that it's not possible to set caching time limits for CSS and JS, especially when you're using a CDN.

    But, now that I've seen this, I guess we can write the rules to .htaccess.

    What is the recommended time to set CSS or JS. I see you have here 1 day or 86400 seconds. Any recommendation on how long to set it to if you're using a CDN.

  6. tonyzeoli
    Member
    Posted 2 years ago #

    This is resolved. I got the answer on the IRC channel from Donncha.

    Settings are what you're comfortable with.

    We're going with 172800 (2 days) for CSS and JS and images at 600 seconds (10 min) because we're a news org that updates stories with images frequently.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic