Current time: 12-09-2019, 03:50 PM Hello There, Guest! (LoginRegister)

Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Expire header on Wordpress php files
01-26-2012, 04:46 PM
Post: #1
Expire header on Wordpress php files
I started looking into cache control headers and one of the thing that stood out is the fact that index.php on the root web folder is not cacheable due to the lack of cache control headers.

When I opened up index.php, all I got is this:
Quote:<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/

/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
?>

Seems like that file isn't going to change for a very long time, so it's probably safe to put a long expire time for it. However, now that I think about it, doesn't all the php files on Wordpress is practically remains the same (only the database content changes from time to time)? Anyway I'd like to hear your opinion on the best way to add a cache header on the index.php and perhaps the other php files as well.

Here is the content of the current .htaccess file on cache control:
Quote:<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/png "access plus 5184000 seconds"
ExpiresByType image/jpeg "access plus 5184000 seconds"
ExpiresByType image/gif "access plus 5184000 seconds"
ExpiresByType text/css "access plus 5184000 seconds"
ExpiresByType application/x-javascript "access plus 5184000 seconds"
</IfModule>

Thanks
Find all posts by this user
Quote this message in a reply
01-26-2012, 10:03 PM
Post: #2
RE: Expire header on Wordpress php files
I don't know much about adding cache control for php files. But, the WordPress (front) page is loaded as text/html file. So, basically the .htaccess file is missing the following directive.

ExpiresByType text/html "access plus 5184000 seconds"

Hope this helps.
Find all posts by this user
Quote this message in a reply
01-26-2012, 11:24 PM
Post: #3
RE: Expire header on Wordpress php files
Don't do it! (unless you REALLY know what you are doing)

Yes, the actual php file itself doesn't change unless you update wordpress but the content it generates does (with every post).
Visit this user's website Find all posts by this user
Quote this message in a reply
01-27-2012, 12:49 PM (This post was last modified: 01-27-2012 12:49 PM by headfonia.)
Post: #4
RE: Expire header on Wordpress php files
Thanks Patrick, so how do I set browser caching on the root index.php file?
Find all posts by this user
Quote this message in a reply
01-27-2012, 11:08 PM
Post: #5
RE: Expire header on Wordpress php files
You don't, unless you don't plan on changing the content of your site. "index.php" is the main entry point for the base page of your site that generates the HTML and it's normal for that to not be cached.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 2 Guest(s)