: HTTP Headers caching I am not totally sure bout HTTP headers, but from what I read its good to have some level of caching on static pages also I am not sure if Transfer Encoding: chunked
I am not totally sure bout HTTP headers, but from what I read its good to have some level of caching on static pages also I am not sure if Transfer Encoding: chunked is a good thing. I was not finding a definite answer as to how best to run this cache with my PHP files so that caching is enabled and when content changes it should update the cache. Hopefully I can get assisted with this, I was wondering which of the following would be best to use or any advice :
header('Cache-control: public');
OR
header('Cache-control: max-age=10');
Thanks for your time.
More posts by @Deb1703797
1 Comments
Sorted by latest first Latest Oldest Best
In Most Cases PHP and HTML Caching is Bad
Generally it is not advisable to cache the PHP and HTML files of a site since when you modified these pages your returning visitors will not fetch the newer page without a hard refresh of the page. It is recommended By Google Insight to cache the images and other files that are unlikely to change. So when you edit images you should save them as a new file name and that way your visitors get the new files even when they have a cache of 2 weeks on media files.
Expires Via .HTACCESS
One of the best ways of controlling expires is via the .htaccess file using the Apache2 expires module.
Below is some recommended code
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType text/cache-manifest "access plus 0 seconds"
#HTML PAGES
ExpiresByType text/html "access plus 0 seconds"
#DATA
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
#RSS
ExpiresByType application/rss+xml "access plus 1 hour"
#FAVICON (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
#MEDIA
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
#HTC TRICK
ExpiresByType text/x-component "access plus 1 month"
#WEBFONTS
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
#CSS AND JAVASCRIPT
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
</IfModule>
In the above example you should use the header append cache-control public.
APACHE DOCS
If you get stuck or have questions regarding the types take a look at: httpd.apache.org/docs/2.2/mod/mod_expires.html
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.