sboire
sboire

Reputation: 184

Cache-control in google app engine

I'm trying to optimize page serving time on Google app engine, but I'm struggling at getting the effect I want.

in my app.yaml, I used the following directive:

handlers:
- url: /assets
  static_dir: assets
  expiration: 7d

under the asset folder, I have all my images, css and js. By using the 7d expiration, I would have expected the browser to use the local cached files and not come to my app for 7 days.

Although, in the response headers for my assets I get the following:

Cache-Control:public, max-age=604800
Cache-Control:no-cache, must-revalidate

I understand that with these headers, the browser will check on my app if the file as changed before releasing the cached version. (I can effectively see a bunch of 304 corresponding to my files under the asset folder, for both refresh and simple page load).

Is there a way in Google app engine to configure the cache behavior so the browser will not comeback for those files for 7d (on a simple page load), as specified in the expiration? (i.e. removing the "no-cache" from cache-control header)

P.S. I dont want to enable PageSpeed on my app. I want full control on the html served.

Upvotes: 8

Views: 4763

Answers (3)

Arjen
Arjen

Reputation: 5313

Are you logged on with an Admin-account by any chance? AppEngine adds some private headers about the costs for Admins and disables caching because that data is private. Logging out solved the problem for me.

Upvotes: 6

deepkimo
deepkimo

Reputation: 3197

How you load your page in the browser might be relevant here:

  • If you press Ctrl and reload the page using the refresh button, that will cause an unconditional reload of your resources with 200s returned.
  • If you just reload using the refresh button (or equivalent key like F5), conditional requests will be sent and 304s will be returned for static resources.
  • If you press enter in the address box, add the page to your bookmarks and load from there, or visit the page from a hyperlink, the cache max-age should work as expected.

Upvotes: 0

user7180
user7180

Reputation: 4066

I didn't use the expiration directive and GAE sends the following as the default cache setting:

Cache-Control:public, max-age=600

Can you try removing expiration: 7d and see if GAE only sends 1 Cache-Control header?

Upvotes: 0

Related Questions