Make PHP page return “304 Not Modified” if it hasn't been modified

前端 未结 4 809
有刺的猬
有刺的猬 2020-12-17 03:33

I have a PHP file that will return the same thing with the same $_GET parameters every time -- it\'s deterministic.

Unfortunately for efficiency (this file is reques

4条回答
  •  -上瘾入骨i
    2020-12-17 04:14

    Without caching the page yourself (or at least its Etag) you cannot really make use of the 304. A full fledged caching algorithm is somewhat out of scope, but the general idea:

    
    //the actual page
    
    

    All common pitfalls apply: you can possibly not display cache pages for logged in users, a caching of partial content could be more desirable, you are yourself responsible for preventing stale content in the cache (possibly using triggers in backend or database on modifications, or just playing around with the getUrlEtag logic), etc. etc.

    You could also play around with HTTP_IF_MODIFIED_SINCE if that's easier to control.

提交回复
热议问题