【问题标题】:How to force refresh of images & css files in CakePHP?如何在 CakePHP 中强制刷新图像和 css 文件?
【发布时间】:2013-01-24 01:28:31
【问题描述】:

我有以下问题。

我正在使用 CakePHP 进行编码,而且我是新手。我经常需要更改网站上的一些图像或 css 文件。在网站上,我总是看到旧内容,除非我手动按键盘上的“F5”。我必须在使用该网站的每个工作场所都这样做。

这很烦人,尤其是因为我不知道在哪里可以找到解决方案。我删除了 tmp 文件和 cookie。没有任何帮助,我不知道该如何解决。

你能帮帮我吗?

【问题讨论】:

    标签: cakephp


    【解决方案1】:

    对于 \webroot 下的任何内容,请参阅 core.php 中的 Asset.timestamp 设置:

    /**
     * Apply timestamps with the last modified time to static assets (js, css, images).
     * Will append a querystring parameter containing the time the file was modified. This is
     * useful for invalidating browser caches.
     *
     * Set to `true` to apply timestamps when debug > 0. Set to 'force' to always enable
     * timestamping regardless of debug value.
     */
        Configure::write('Asset.timestamp', true);
    


    为此,您必须使用 Cake 助手来创建资产(例如 $this->Html->image()$this->Html->css() 等)

    【讨论】:

    • 非常感谢! 'Asset.timestamp' 正是我所需要的。
    • 如何向 CakePHP 资产文件(JS 和 CSS)添加版本?
    • Cake 是否会自动知道使用旧时间戳刷新文件,还是您仍需要通过 Configure css.php 过滤器将其传递?例如,我在 UrlHelper.php 中看到一个命令据说会自动执行此操作。
    • @liquified 只要您使用助手,Cake 就会处理版本控制。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 2011-01-13
    相关资源
    最近更新 更多