0

I am copying an image to Google Cloud storage and want it to be available publicly via a URL. I want the browser to use its cached version when available.

I do

gsutil -h "Cache-Control:public,max-age=3600" cp -a public-read -r path/file.png gs://my_bucket/

However, the browser does not show status 200/cached for this image. Instead it's status 304. (I am within the 3600 time limit that I have set in this case.)

user984003
  • 28,050
  • 64
  • 189
  • 285

1 Answers1

1

That's the expected behavior. 304 means "not modified," so the browser should use the cached value.

See the w3 spec. From the docs:

If the client has performed a conditional GET request and access is allowed, but the document has not been modified, the server SHOULD respond with this status code. The 304 response MUST NOT contain a message-body, and thus is always terminated by the first empty line after the header fields.

elixenide
  • 44,308
  • 16
  • 74
  • 100
  • According to this http://stackoverflow.com/questions/1665082/http-status-code-200-cache-vs-status-code-304 status 304 is slower and actually makes a request to the server. I don't want that. – user984003 Aug 15 '15 at 20:07
  • @user984003 well, that's a somewhat different question. You can't prevent the browser from making a request for a resource at all. You certainly can't do it by using HTTP status codes. HTTP status codes are only relevant when there has already been a request to the server; they are sent as part of the response. – elixenide Aug 15 '15 at 20:10
  • @user984003 the answer you linked to has to do with when the browser uses its *own* cache. Whether it does so depends on user settings. You, as the site owner, cannot control what the browser does with respect to its own cache. You can only tell it what you think it should do. – elixenide Aug 15 '15 at 20:12
  • If I go to google.com then the logo image is loaded with a status 200/cached. So my browser is set up to use cache. I want this same behavior from the image in google storage cloud. – user984003 Aug 15 '15 at 20:14