• WP Super Cache rocks. There are a couple of things I cannot figure out though and was wondering if anyone has any suggestions.

    1. Is it necessary to have WP Cache enabled with Super Cache? It appears to be that everything being cached by WP Cache is also cached by WP Super Cache and items are served from WP Super Cache by priority.

    2. Is there a way to disallow content from being served based on user agent? I have figured out this is easy to do with rewrite rules for WP Super Cache but the default WP Cache I have not been able to figure out unless I just set “$cache_enabled = false;” in wp-cache-config.php. WP Super Cache still works in this situation as far as I can tell… cache files are created and served.

    3. I was going to look at attempting to write a plugin but I am not a great coder and was having trouble finding documentation based on the WP Super Cache plugin section.

    My overall goal is to serve different CSS files for mobile clients. I currently can do this by adding the mobile user agents to WP Super Cache so they do not cache files, then by adding rewrite rules to .htaccess in /, and last but not least by disabling WP Cache. Just not sure if this is the correct way to do things.

    Any thoughts or suggestions are appreciated. Thanks. -Alex

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter narfonix

    (@narfonix)

    Oops. I was incorrect above. Having “$cache_enabled = false;” in wp-cache-config.php disables WP Super Cache caching but still serves the already cached pages.

    Basically I have to find a way to redirect user agents just away from wp-cache since I am already able to do so away from wp super cache.

    Thread Starter narfonix

    (@narfonix)

    Does anyone have any ideas how to route certain user agents around WP Cache?

    Yes, use the exclude options in the admin page.

    Thread Starter narfonix

    (@narfonix)

    Hello donncha. Thanks for the response.

    I am not familiar with the exclude option. Could you explain more? Are you talking about the rejected UA strings? If so doesn’t this only prevent these user agents froom creating cached pages? How would you prevent a user agent from picking up a cached page. My goal is to have pages cached by say a user agent of IE so the next IE user would pick up a cached page but a user agent of BlackBerry would not pick up the same cached page.

    Any help is appreciated. Thanks.

    You can exclude certain browsers from generating cached files, but you can’t stop those user agents from being served cached content.

    If you switch the plugin to half-on mode, and write a supercache plugin that hooks into the “wp_cache_get_cookies_values” action you can make cache files user-agent dependent so an IE user will only ever see the IE cached page.

    Thread Starter narfonix

    (@narfonix)

    OK. Not sure I am advanced enough to write that hook but I will attempt here in the near future to see if I can.

    I appreciate the response and the suggestion. Seems like a logical way to make it successful.

    Thanks again.

    If you want to exclude certain user-agents from seeing static-cached pages, you just need to add some RewriteCond statements to the root .htaccess.

    i.e. to block all user-agents with “bot” in their name you’d just add a RewriteCond to the beginning of the 2 rewrite rules WP Super Cache inserts into .htaccess like this:

    # This very first RewriteCond is the new one:
    RewriteCond %{HTTP_USER_AGENT} !bot
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
    RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]

    (and then the same RewriteCond added before the next rule, which sends browsers to non-gz static pages)

    Here’s what I did to solve this problem:

    I wanted to prevent iPhone browsers from generating super-cached HTML as well as from receiving super-cached HTML from previous hits.

    1. In the WP-Super-Cache settings page, I added “iPhone” to the “Rejected User Agents” list (as well as iPod, Android, BlackBerry, etc). You can get a list of these from wp-cache-config.php. This prevents any hits from an iPhone from generating a cached file.

    2. In my /.htaccess file, I added these lines to the WP-Super-Cache Rewrite conditions to prevent iPhone user agents from receiving any cached files that have been generated:

    # BEGIN WPSuperCache
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    AddDefaultCharset UTF-8
    RewriteCond %{REQUEST_URI} !^.*[^/]$
    RewriteCond %{REQUEST_URI} !^.*//.*$
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
    # ADDED THIS LINE TO PASS-THROUGH MOBILE USER AGENTS
    RewriteCond %{HTTP_USER_AGENT} !(iPhone|iPod|Android|Danger|Playstation|BlackBerry)
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
    RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]
    
    RewriteCond %{REQUEST_URI} !^.*[^/]$
    RewriteCond %{REQUEST_URI} !^.*//.*$
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} !.*=.*
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
    # ADDED THIS LINE TO PASS-THROUGH MOBILE USER AGENTS
    RewriteCond %{HTTP_USER_AGENT} !(iPhone|iPod|Android|Danger|Playstation|BlackBerry)
    RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
    RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
    </IfModule>
    # END WPSuperCache

    Seems to work so far…I’ll have to do some more testing.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[WP Super Cache] Couple of questions?’ is closed to new replies.