I have a great .htaccess code which really improve my page speed.
This one below I below I don't really know much but from looking at it is like to compress or something not really sure
<FilesMatch ".(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
This one is really great which set the Expire header for everything to 10 years and text/html to one day
ExpiresActive On
ExpiresDefault "access plus 10 years"
ExpiresByType text/html "access plus 1 day"
So This one is use to unset ETag which is one of the requirement rules of YSlow
Header unset ETag
FileETag None
Now come to my question that I have problem with.
I can't really use w3 Total cache with my Wordpress blog because it gives me some random issue like only show one ramdom old post to my home page and to solve that is to delete the cache and then after a day it will happen again.
So I can't rely on that plugin, but with my 3 codes that I added in my .htaccess is really good with one exception and I don't know really how to fix that.
say for example I visit my site http://applesiam.com this morning and during the day I have 3 new posts. If I don't really do hard reload page I will still see the one from morning.
So this is really make me confuse.
What should I change to not to cache the actual home page so it will be updated except images and the rest.
I'm not sure if this is going to work but I found this which is going to solve the behaviour of the browser cache the file that update dynamically
# Force no caching for dynamic files
<filesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</filesMatch>
Related
I have set the page header to the public by htaccess file.
<ifModule mod_headers.c>
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|css|js)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
<filesMatch "\\.(html|htm|php)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
</ifModule>
But still, it is showing cf-cache-status: as DYNAMIC for the static HTML page too. Please let me know if there is an additional setting at Cloudflare or the website header.
I'd recommend to review the Default Cache Behaviour documentation page which explains how the Cloudflare Cache works and how to configure it to cache (or bypass caching) different resources. To summarise:
By default only specific file extensions are cached
You can set specific Page Rules to override the default behaviour
You can also use Cloudflare Workers to achieve a customized caching result
You can also use Cache-Control headers, as long as the resource is deemed cacheable (see above)
Let me first mention that I have done some digging but can't seem to find a proper answer to what I'll looking for.
I'm working on a site where I am using a few external resources:
Google Analytics (//www.google-analytics.com/analytics.js)
Latest jQuery version (http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js)
Google Fonts (http://fonts.googleapis.com/css?family=Lato:400,300)
Use a Content Delivery Network (CDN)
I'm getting an "F" grade on "Use a Content Delivery Network (CDN)". A different SO Post links to the YSlow FAQ (direct link) but this seems to indicate that I need to define my CDN's on my browser, which seems to be a quick fix for me, but this does not solve the problem on other browsers and/or devices.
Add Expires headers
As for the "Add Expires headers" grade,I get an E. Problem is, this is what I'm getting:
There are 3 static components without a far-future expiration date.
(2014/2/26) http://fonts.googleapis.com/css?...
(2014/2/26) http://www.google-analytics.com/analytics.js
(2014/2/26) http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js
How would I go in order to correct this? My local files are all taken care of by my .htaccess as shown, here:
AddType image/x-icon .ico
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/ico "access plus 1 year"
ExpiresDefault "access plus 7 days"
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
# access plus 1 year
Header set Cache-Control "max-age=31536000"
</FilesMatch>
This SO post seems to suggest it is either impossible, or I call upon a local script where I use my bandwidth to load (and cache) the required external files.
So, with these things in mind, here is what I'm looking at:
External ressources should be CDN's, but YSlow reads my local preferences which will vary from user to user, so I need an alternative to the about:config solution proposed by the YSlow official site.
Expires are set by the server where the file is, so I don't seem to have access to defining it's expiration values. So, from what I gather, I could carry these files onto my server or use a local PHP file and cache it from said PHP file located my server, but this doesn't seem optimal. Is there a way to go around this?
Short answer:
You can't control much when you're loading resources from external servers like that, but it may still be okay for your site. When using a tool like YSlow it's important to not get caught up into an "A" grade for everything. It's best to understand the hints the tool is giving you, and make decisions accordingly.
Longer answers:
Content Delivery Network
YSlow will report lower grades for any domains it doesn't recognize as a CDN. You can add CDN hostnames, then it will reflect a better grade. I would add fonts.googleapis.com and ajax.googleapis.com because both behave like CDNs. Think of it as saving a preference in your copy of YSlow. Adding the domains here doesn't actually change your performance, it just improves your score.
Expires Headers
You can't control expires headers for content you're loading from a different site. Options you could consider:
Continue using external sites; in this case these are pretty well behaved and your performance will probably be pretty good. Just ignore the low grade that YSlow is giving you.
Host your fonts and jQuery files locally, then set far-futures expires headers as you've shown in your .htaccess. This would give you a better YSlow grade, but actual performance may be worse if your server is slower than the CDNs. (see this SO question)
Use external sites but adjust your URL; in the case of jQuery, if you specify on more version level (1.8.0 instead of 1.8) you will get a far future expires header (see this SO question)
So I was reading in the joomla wiki but could not find any further details than general talk.
So what I basically want to change is what is being loaded. For the simple main page of my blog joomla loads a a truckload of files, and a a big part is not cached. I want to introduce a caching mechanism and remove the things I am sure I don't need.
So what I in detail want to know is where is:
<jdoc:include type="head"/>
implemented?
If a tool exists to realize the caching in a easier fashion than actually writing it myself, i'd be very thankful as well. I am talking about caching pictures, css and javascript files by setting expire to in one year. Afterwards invalidating the cached files by adding a version number to the request string.
I am citing RedEye from the joomla forums:
"The file is in /libraries/joomla/document/html/renderer/head.php
But don't change this file, make an override. Copy it somewhere (your template folder for example) and include the file in your template index.php"
I'll have a go at this as soon as I finished what I started in the meantime
I find the JCH Optimize plugin works really well in combining, minimizing, and caching JavaScript and CSS files. There's a free and paid version of it. You can have it just cache the main Joomla core and template files, or you can have it do some or all of the extensions that you have in your install too. You can exclude certain files if you run into a problem. You may have to play with the plugin order and put this one towards the bottom of the list so that it loads later and grabs most of the files to optimize.
For images: If you're using an Apache web server, you can add ExpiresByType rules in the .htaccess file or httpd.conf or a conf.d file. I wouldn't include the css and js files here because I would let JCH Optimize handle them. Most of my sites have changing content so I don't typically set that very far in the future. Here's some sample code you could use.
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive - covers html, etc
ExpiresDefault "access plus 3 minutes"
# My favicon
ExpiresByType image/x-icon "access plus 1 year”
# Images
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"
</IfModule>
For more reading, see the Apache docs on it.
Finally, jQuery can be sourced from Google using another handy free extension called jQuery Easy. You can even set it to load jQuery securely (https). Sorry, I don't have enough points to post a link.
When a browser requests a jpg and the server returns the data but not as a reference to a jpg file but rather sends the jpg data itself, is it possible for the browser to cache the data?
For example:
http://www.somewebsite.com/image/abc
This uri returns jpg data. Is there some way to get the browser to cache the data it receives to avoid having to request it again?
I just attempted to debug your example but received an Account Suspended. Webmaster, please, contact support. page!
So as I am working blind can I suggest researching the header('Expires: SOME DATA HERE') function in PHP (I assume you are using PHP).
If the solution does not lie there you can also use .htaccess to set the headers using
<IfModule mod_expires.c>
ExpiresActive On
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>
This example taken from http://www.robertwent.com/blog/servers-and-hosting/45-set-expires-headers-in-htaccess
Ultimately it is the headers that tell the browser how you advise the content is cached. What the browsers actually does can sometimes be surprising.
I have a page index.php which depending on the arguments provided generates different output.
Using mod_rewrite i have those files a a.htm, b.htm and c.htm .
Now, i want these particular 4 Files (or URLs actually) to be cached locally,
for that i have tried
<FilesMatch "(a\.htm|b\.htm|c\.htm)$">
FileETag None
Header set Cache-Control "max-age=7200, public, must-revalidate"
</FilesMatch>
But it doesn't work.
how do we go about this issue ?
RewriteEngine on
RewriteRule index.htm index.php
<FilesMatch "index.htm">
FileETag None
Header set Cache-Control "max-age=7200, public, must-revalidate"
</FilesMatch>
This is a sneak peak of what i have right now. But in the long run there will be lots of files and rewritten url's. so i want to add cache headers via htaccess . hope it makes sense !