douhai5835 2016-02-12 05:53
浏览 70
已采纳

Web浏览器是否以不同方式缓存HTML文件和PHP生成的文件?

I'm using Nginx as web server and Firefox to view response headers. For testing, I had two files on the server with the same content: test.html and test.php. In the Nginx configuration file, the expires directive is set to 30d in the server context.

When accessing test.html in a web browser multiple times, the browser first obtains a 304 Not Modified response and serves a copy cached in the browser. However, when accessing test.php, the browser always makes a full request to the server (200 OK) without using the browser cache.

The questions are:

  1. Is the behaviour (i.e. different treatment of HTML and PHP generated files) normal?
  2. What could be done to make web browsers cache HTML and PHP generated files in the same way?
  • 写回答

1条回答 默认 最新

  • doufeng1249 2016-02-12 06:14
    关注

    nginx sets the response header for the static file, included in the headers are:

    • Cache-Control
    • Expires
    • Last-Modified

    Cache-Control tells the client (at least) how to cache the content.

    Expires and Last-Modified allow the client to determine when to fetch new content.

    What you must do is ensure that PHP sends the same headers, or sensible headers if not exactly the same; Now that you know which headers are important, inspecting the requests in your browser will tell you how to achieve this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分