javascript - 如何在 PHP 中控制缓存
问题描述
我正在开发基于 Php 的电子商务网站,但我没有使用 Apache 作为服务器,而是创建了自己的自定义服务器脚本,如下所示:
我有 Index.php 我把所有路由放在哪里,它工作正常但是当我尝试实现缓存控制时,它不会适用。
这是目录结构:
--src
--public
--index.php
--.htaccess
--views
我认为我的 .htaccess 文件无法正常工作,没有图像、css、js 缓存到内存中
这是 .htaccess 代码
# Leverage Browser Caching
<IfModule mod_headers.c>
Header set Connection keep-alive
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=2678400, public"
</filesmatch>
<filesmatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
<filesmatch "\.(pdf)$">
Header set Cache-Control "max-age=86400, public"
</filesmatch>
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=2678400, private"
</filesmatch>
</IfModule>
解决方案
推荐阅读
- encryption - Casear Cipher 蛮力攻击 - 每一个可能的密钥
- python - BytesIO Python 的克罗地亚语编码
- java - Java GUI GridBagLayout 如何在一列中放置三个组合框?
- c# - 我可以在字典中存储类型或类型名称并在 C# 的泛型方法中使用它吗?
- jestjs - 如何用玩笑测试 objection.js?
- authentication - keycloak登录后无法重定向回应用程序页面
- javascript - Angular 6 'app-action-button' 不是已知元素
- memory - 防止极端内存使用
- nginx - NGINX proxy_pass URL 带参数到另一个路径
- ruby-on-rails - 控制器在哪里定义为某个操作呈现什么模板或视图?