Yii 是否缓存外部 javascript 文件和 CSS 文件?
Yii 是否缓存外部 javascript 文件和 CSS 文件?
我想使用 Yii 缓存来缓存我的主页。 我的主页文件非常小(不包括js和css)。我的数据库中的缓存大小为 5.7K。
我想知道 Yii 是否缓存外部 js 和 css 文件?
我确实认为它不会缓存外部图像文件。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Yii 可以几种不同的方式缓存它生成的动态内容 将其存储为静态内容,包括缓存 数据库结果,页面片段等任何东西从数据库查询并由 PHP 动态转换为 HTML 文档可以由框架缓存。
CSS、JS 和图像(通常)已经是静态内容,框架不会生成这些内容,因此无法缓存它们。
静态内容主要缓存在客户端的 Web 浏览器中,或快速分布式内容交付中(CDN) 服务器。
也就是说,Yii 可以做一些事情来帮助加速 CSS 和 JS:
Yii 的 CAssetManager< /a> 允许您使用 Yii 压缩静态脚本(使用第 3 方工具),然后“缓存”优化后的脚本(在
assets
文件夹中)。这也可以通过服务器脚本和扩展来完成。您还可以指定不同的缓存后端,例如 Memcached和 APC,Yii 将存储它缓存的 HTML,但这不会直接影响您的图像和 CSS/JS。
Yii can cache the dynamic content it generates a couple of different ways by storing it as static content, including caching database results, page fragments, etc. Anything queried from the database and dynamically turned into an HTML document by PHP can be cached by the framework.
CSS, JS and Images are (usually) already static content, which the framework is not generating, so it cannot cache it.
Static content is mostly cached in the client's web browser, or on fast distributed content delivery (CDN) servers.
That said, Yii can do a few things to help speed up CSS and JS:
Yii's CAssetManager allows you to use Yii to compress your static scripts (using 3rd party tools) and then "cache" the optimized scripts (in the
assets
folder). This can also be done with server scripts and extensions.You can also specify different cache backends, like Memcached and APC, where Yii will store the HTML it caches, but again that does not directly affect your images and CSS/JS.