Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why digest are used in Rails 4 for static content instead of ETag

I think that HTTP's ETag is exactly the mechanism for invalidating stale cached content. And digests are used for the same sake. Why are they better and why etags are not enough?

like image 608
Konstantin Tikhonov Avatar asked Sep 30 '22 16:09

Konstantin Tikhonov


1 Answers

Because ETags still require the client to hit the server to see if the client's cached copy is still fresh. Rails puts a far future expires header on assets which means that the client will never hit the server again for an asset, it already has cached. Digests then become the means for the server to make a client get a new version of the asset. I think Rails used to use timestamps instead of digests, but digests have the added, small benefit that if you revert the asset back to its previous state, its digest will be the same, and the client may still have it cached.

like image 143
KaptajnKold Avatar answered Oct 03 '22 03:10

KaptajnKold