简体   繁体   中英

Http headers to cache a dynamic page

I have a classic html page generated with PHP.

For this page (served from a same URL) we have 2 cases:

  1. The user is logged (cookie based) => the page is specific to the user (we display a box with user name + personal information.)
  2. The user is not logged in => the page is common to all the user.

How can I set the header to:

  • have the most agressive cache (with a max-age of 60).
  • avoid mixing pages between users.

Can I replace my present header:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

With this?

header('Cache-Control: public, max-age=60');
header('Vary: *');

Edit : Is it possible (how) to have it Cache-controled private in case "1" and public in case "2"

If login is purely cookie based then you only need a Vary: Cookie header to make it unique to a particular user. The Vary: * should work just as well though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM