4

I have an Apache with http2, and I have made a server push of files which I would like to save on browser cache, but it doesnt and I dont know why.

I have made the push with a php file, the following one.

header( 'Link: <'https://www.myweb.com/mypath'>;rel="preload";as="video"', FALSE );

From my point of view, the Server push is working, because I can see the requests to the server in the access_log, but I think that the files should be saved on the browser cache, but It doesnt.

I try to make a server push of a file, and after it, request this file and get it from cache (see on the Network console of Chrome "from cache").

Thanks

Castaglia
  • 2,972
  • 5
  • 28
  • 49
Elo
  • 137
  • 1
  • 9
  • Do you verified the `Cache-Control` headers of the pushed content? Which one it have? One can set `public, max-age=somevalue`, `expires`, `etag` and `last-modified`. If on the other side "private", "no-store" or "no-cache" are set then server push will don't help you. Server push just place the data in the local cache of the web browser. The `Cache-Control` header specify whether the data from the cache will be used and how long it will be used. – Oleg Mar 21 '16 at 16:53
  • I have thought about that, but I dont know where to set this parameters. If I put the URL of the file which I am pushing, the file is downloaded and saved on cache, because it has the parameters you said. But it seems that when I make the push, it has no parameter. I dont know if I have to set some parameter in the line of the push (header...). – Elo Mar 21 '16 at 18:24
  • 1
    IMO, configuring caching correctly even for a HTTP/1.1 website is hard any time of the year. Combining it with HTTP2 Push is still harder. [Here is an article](https://www.shimmercat.com/en/info/articles/caching/) with some details on how to combine the query parameter, do push and so on. Full disclosure, we created much of the server just to get this right, and we are still on our way. – dsign Mar 21 '16 at 19:50
  • @dsign: I personally find the best scenario: the usage of **immutable** URLs. For example URL `https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js` is immutable because it contains the version number. The next version will get *another* URL. Thus one can set really large value for `max-age`: 1 year for example. The only thing is not simple: the client should know that the pushed file *already exist* in local cache and should inform the server to suppress pushing. It's not so simple to implement the scenario in common case, but it simple if *block of files* changed simultaneously. – Oleg Mar 21 '16 at 23:21
  • @Oleg Knowing about which URLs the client have in cache is the content of [this proposal](https://tools.ietf.org/html/draft-kazuho-h2-cache-digest-00). There are some JS polyfills for the browser side. And the other possibility currently implemented by H2O and by ShimmerCat is to account for the client's cache digest with the help of cookies. – dsign Mar 22 '16 at 06:13

1 Answers1

0

All you said was true, and I had it on my code, but the trouble was on the understanding of the Google Chrome Cache saving.

When you send some file with Server Push on an HTTP2 connection, the file requested via server push is sent as response to the client, but Google Chrome does not save it into Google Chrome cache until the file was requested by the browser.

For example: The server sends the response of index.html with its stylesheet.css (this one sent with server push). The stylesheet will only be saved into Google Chrome cache when Google Chrome request the Stylesheet.css(the client has requested only the index html and make a push of the stylesheet). If Google Chrome does not request it, it will be an unclaimed push and it will not be saved into cache.

If you have a success push, and reload the page, you will see "from cache" on Google Chrome.

Thanks for your time.

Elo
  • 137
  • 1
  • 9