4

I am testing my website on webpagetest.org. It gives me a

enter image description here

and then goes on to give this list:
Leverage browser caching of static assets: 63/100
WARNING - (2.0 hours) - http://stats.g.doubleclick.net/dc.js
WARNING - (5.5 days) - http://www.bookmine.net/css/images/ui-bg_highlight-soft_100_eeeeee_1x100.png
WARNING - (5.5 days) - http://www.bookmine.net/favicon.ico
WARNING - (5.5 days) - http://www.bookmine.net/js/index.min.js
WARNING - (5.5 days) - http://www.bookmine.net/js/jquery-ui-1.8.13.custom.min.js
WARNING - (5.5 days) - http://www.bookmine.net/css/index.css
WARNING - (5.5 days) - http://www.bookmine.net/js/jquery.form.min.js
WARNING - (5.5 days) - http://www.bookmine.net/css/jquery-ui-1.8.13.custom.css

funny thing is that it does recognize I have caching enabled (set to 5.5 days as reported above), then what is it complaining about? I have also verified I have a default_expiration: "5d 12h" set in my app.yaml and from this link:

default_expiration

Optional. The length of time a static file served by a static file handler ought to be cached by web proxies and browsers, if the handler does not specify its own expiration. The value is a string of numbers and units, separated by spaces, where units can be d for days, h for hours, m for minutes, and s for seconds. For example, "4d 5h" sets cache expiration to 4 days and 5 hours after the file is first requested. If omitted, the production server sets the expiration to 10 minutes.

For example:

application: myapp version: alpha-001 runtime: python27 api_version: 1 threadsafe: true

default_expiration: "4d 5h"

handlers: Important: The expiration time will be sent in the Cache-Control and Expires HTTP response headers, and therefore, the files are likely to be cached by the user's browser, as well as intermediate caching proxy servers such as Internet Service Providers. Once a file is transmitted with a given expiration time, there is generally no way to clear it out of intermediate caches, even if the user clears their own browser cache. Re-deploying a new version of the app will not reset any caches. Therefore, if you ever plan to modify a static file, it should have a short (less than one hour) expiration time. In most cases, the default 10-minute expiration time is appropriate.

I even verified response my website is returning in fiddler:

HTTP/200 responses are cacheable by default, unless Expires, Pragma, or Cache-Control headers are present and forbid caching. HTTP/1.0 Expires Header is present: Sat, 26 Sep 2015 08:14:56 GMT

HTTP/1.1 Cache-Control Header is present: public, max-age=475200 public: This response MAY be cached by any cache. max-age: This resource will expire in 132 hours. [475200 sec]

HTTP/1.1 ETAG Header is present: "74YGeg"

So why am I getting a D?

Adding some useful links:
- http://www.learningtechnicalstuff.com/2011/01/static-resources-and-cache-busting-on.html
- http://www.codeproject.com/Articles/203288/Automatic-JS-CSS-versioning-to-update-browser-cach
- https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#invalidating-and-updating-cached-responses
- https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
- https://stackoverflow.com/a/7671705/147530
- http://www.particletree.com/notebook/automatically-version-your-css-and-javascript-files/

Community
  • 1
  • 1
morpheus
  • 18,676
  • 24
  • 96
  • 159

1 Answers1

5

WebPagetest gives a warning if the cache expiration is set for less than 30 days. You can view that detail by clicking on the "D" grade in your test results and viewing the glossary for "Cache Static". You can also find that info here.

If you need to modify a cached static javascript file, you can add version number to the file path or in a querystring.

Jeff Deskins
  • 1,650
  • 1
  • 10
  • 9
  • thanks. could you explain how to deal with this comment: if you ever plan to modify a static file, it should have a short (less than one hour) expiration time. I guess you already mentioned about using version number and it sounds like a perfectly good solution, but would be interested to know if you have more tips and best practices to share. – morpheus Sep 21 '15 at 16:32
  • I generally try to have the static files cached for 30+ days. For those times that I need to push a change, for example an updated javascript file, then I modify the version number in the file path. If you don't have a build architecture that will dynamically generate a version directory in your static path, then you can simply call your javascript file with the version number in the querystring. An example would be: src="http://example.com/static/myfile.js?ver=123" – Jeff Deskins Sep 21 '15 at 17:50
  • @JeffDeskins Today I tested my website on Webpage test, it's showing same for my rest api calls. Rest api calls are not static assets. How can I solve it? – Vaibhav Kumar Jun 12 '18 at 13:42
  • @VaibhavKumar It may be due to the API returning mime type that is text or javascript that doesn't explicitly have an Expires header of 0 or -1. More info at http://www.webpagetest.org/performance_optimization.php - look under Applicable Objects in Cache Static section. – Jeff Deskins Jun 13 '18 at 03:11
  • @JeffDeskins All apis returning JSON object. the content type for them is `Content-Type: application/json`. Is it good to set header for the apis? – Vaibhav Kumar Jun 13 '18 at 08:17