-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Leverage Browser Caching #134
Comments
I have often found that recommendation on Pingdom too, so this sounds like a good idea to me! |
+1 |
I agree, so long as the site owner knows what they are doing. Currently, QC doesn't impact static content on the site at all; i.e. images, JS, CSS, etc. That is, the site continues to leverage browser caching on those resources in whatever way it chooses to do so. However, QC does (by default) send no-cache headers to the browser for PHP (i.e. dynamically generated content) built by WordPress. You can turn this on/off if you prefer though. That's already possible. Generally speaking, if it has a Remember, when QC sends a no-cache header, that doesn't impact static resources, it only impacts the HTML that loads them. In other words, the benefit of sending a no-cache header when serving content generated via PHP, far outweighs the very tiny performance hit there IMO. This is what allows your site to remain dynamic. Imagine a user that visits Page A for the first time while logged-in. Their browser caches that version of the content. Now they log out of the site. The next time they visit Page A they will still see the same page they saw while logged into the site, because that's the version of the content that their browser cached first. Should it still be the same? No! Might it have their username at the top? Or maybe a link that says "logout"? ; even though they are no longer logged-in. See how this might create confusion? Of course, that's just one scenario. On a site that generates content dynamically, there could be a few other scenarios similar to this one, where having one variation in the cache, might result in a visitor NOT seeing what you intended for them to see on a return visit. This is particularly hairy when your site operates on sessions or other client-side cookie values in one way or another. All of that said, if getting every ounce of speed possible is more important that maintaining the integrity of the site itself (i.e. to be able to dynamically alter the HTML output via PHP when you need to); then you can certainly allow a browser to cache dynamically generated content. That's fine if you know exactly what you're doing. It would help to reduce the overall number of HTTP connections that your server deals with. It's just important to realize the impact of such a decision. |
@jaswsinc Thank you for sharing your thoughts. That's definitely a very important point. I wasn't under the impression that this GitHub issue was referring to caching HTML in the browser. This is about allowing browser caching for all other resources that are more likely to be static, e.g., JS and CSS files, image files, and any other binary files that are unlikely to change. See this overview description from the Google PageSpeed Leverage Browser Caching recommendations page.
|
What I'm thinking is a section of Quick Cache that makes a recommendation for what should be inserted into their main Here's an example of what that might look like:
|
@raamdev I see, thank you. Here is what I use in Apache to achieve this.
|
I agree with you on that. Great idea! |
Note the default value of |
Very good to know. Thanks for the tip! :) |
I agree that we could certainly do this for them. I don't see any harm in doing so. So long as it's optional. |
Just a couple of comments as a user, not a programmer:
For example, I would think that anyone wanting to cache content for logged-in users should really be using that specific feature in QC Pro (especially if you're able to get s2Member to permit that without causing other issues). Thanks again! |
@KTS915 Thank you VERY much for the feedback. :) That's very helpful. |
I found the following example configuration from @jaswsinc in my notes that I'm copying here for reference:
See also, more information on leveraging browser caching: http://gtmetrix.com/leverage-browser-caching.html |
@raamdev Since I originally posted that example, I spent some time going back through and trying to bring my own configurations up-to-date and also tried to simplify things just a bit further.
Instead of disabling ETags, which actually help to alleviate the burden on a server, we can leave them enabled; and just exclude the INode. This way when caching is allowed, a browser can also use ETags to further optimize itself. Instead of needing to worry about individual MIME types, we can throw a simple default So what does that mean?
Outside of WordPress, the case would be the same. If dynamic content wants to override the default In a case where a site owner wants to get more specific they could add new entries for various MIME types of their choosing. Anyway, just my thoughts. You might prefer to provide the example with a full list of MIME types. I think either way would be fine. Just wanted to point out that it doesn't necessarily need to be as complicated as my original example.
|
But wouldn't that mean if WordPress (or maybe another WordPress plugin) did not explicitly override the default It's my understanding that by explicitly defining what file types should be cached we can avoid any possibility that dynamic HTML might accidentally get cached by the browser. Is that correct? |
That's correct. I don't see that as a bad thing though. It really just simplifies thing a bit. If the content does not state that it's NOT to be cached, it's left up to a browser anyway. For instance, if you access any file on the server and that file does not set an In short, if a file should not be cached, headers should be sent to a browser. The following just establishes the default base that we start from.
|
Got it. Thank you for explaining that. I haven't looked into how WordPress Core handles this, but I assume it's pretty consistent with sending the necessary no-cache headers when it should, correct? |
Yes, WordPress seems to do a good job of controlling the cache behavior on it's own; when it comes to the back end. Anything in the admin sends If we leave ETags enabled too, then a browser may actually cache it even longer than this; so long as the server says |
Perfect. I agree then that it makes sense to keep things simple and leave the ETags enabled. In the configuration panel, I can maybe have an expandable section that explains how things can be tweaked further if setting expire times for specific file types is desired (or just link out to a wiki article). |
+1 for this request. |
👍 |
Noting that I had 1 request today via Quick Cache Pro support for this request. |
+1 for this request. |
+1 |
What's the next step here? |
Noting that work on this feature has started in #765. |
Comet Cache v160706 has been released and includes changes from this GitHub Issue. See the v160706 announcement for further details. This issue will now be locked to further updates. If you have something to add related to this GitHub Issue, please open a new GitHub Issue and reference this one (#134). |
Google PageSpeed Insights Analysis often recommends to site owners that they "leverage browser caching".
Several Quick Cache users have inquired about this and I think it would be a good idea to add this feature to Quick Cache Pro.
Requested here:
http://wordpress.org/support/topic/how-to-leverage-browser-caching-1
http://wordpress.org/support/topic/google-pagespeed-insights-suggests-leverage-browser-caching
Related: #255 #371
Next Actions
.htaccess
file (this should be a universal method that can be used for inserting other code into.htaccess
as well, such as GZIP Compression).htaccess
is not writable, a notice should be displayed indicating as much and show the Browser Caching code that needs to be manually inserted into the root.htaccess
file.admin_init
detect if Browser Caching option is enabled and Browser Caching code is not found in.htaccess
file, it should display a warning.htaccess
, ZC should not send no-cache headers.The text was updated successfully, but these errors were encountered: