CSS Pagespeed缓存css,开发很烦

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4997217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:43:25  来源:igfitidea点击:

Pagespeed caching css, annoying to develop

csscachingpagespeed

提问by patnz

I'm working on a site which I havent coded from scratch and in firebug the css files are being displayed as: style.css.pagespeed.ce.5d2Z68nynm.css with the pagespeed extension. Can anyone tell me what's doing this as I can't find it. I'm guessing mod-pagespeed possibly running on server? I want to turn it off for now because it's caching my css and stopping updates which is really annoying to develop with.

我正在一个我没有从头开始编码的网站上工作,在 firebug 中,css 文件显示为:style.css.pagespeed.ce.5d2Z68nynm.css 和 pagespeed 扩展。谁能告诉我这是怎么回事,因为我找不到它。我猜 mod-pagespeed 可能在服务器上运行?我想暂时关闭它,因为它正在缓存我的 css 并停止更新,这对于开发来说真的很烦人。

Thanks in advance.

提前致谢。

回答by chirale

Alister is right. There are other two ways I know to do this. With a .htaccess shared through many domains and you want to disable PageSpeed only on a single domain, you can add to the bottom of the .htaccess file:

阿利斯特是对的。我知道还有其他两种方法可以做到这一点。通过多个域共享 .htaccess 并且您只想在单个域上禁用 PageSpeed,您可以添加到 .htaccess 文件的底部:

<IfModule pagespeed_module>
  ...
  ModPagespeedDisallow http://www.example.com/*
</IfModule>

It means that you can have two domains, one for the developement (ModPagespeedDisallow) and one with ModPagespeed active. Never tried but should it works, avoiding visitor getting a not optimized page during development.

这意味着您可以拥有两个域,一个用于开发 (ModPagespeedDisallow),另一个用于激活 ModPagespeed。从未尝试过,但它应该有效,避免访问者在开发过程中获得未优化的页面。

Or you can add ?ModPagespeed=offto the url as stated on mod_pagespeed FAQ.

或者您可以添加?ModPagespeed=offmod_pagespeed FAQ 中所述的 url 。

回答by Alister Bulman

According to http://code.google.com/speed/page-speed/docs/using_mod.html#htaccessyou can turn off the module with the line ModPagespeed offin a .htaccess file.

根据http://code.google.com/speed/page-speed/docs/using_mod.html#htaccess,您可以ModPagespeed off使用 .htaccess 文件中的行关闭模块。

The best solution would be to have a non-live development environment that didn't have mod_pagespeed on at all, or where it could be added only for some final testing.

最好的解决方案是拥有一个完全没有 mod_pagespeed 的非实时开发环境,或者只能在某些最终测试中添加它。

回答by Dorad

Another option for resetting the cache is described here:

此处描述了重置缓存的另一个选项:

Find out where is the cache folder, it's defined in the config file under ModPagespeedFileCachePath property.

找出缓存文件夹在哪里,它在配置文件中的 ModPagespeedFileCachePath 属性下定义。

Then run the following command from shell:

然后从 shell 运行以下命令:

touch <path_to_pagespeed_cache>/cache.flush
(In my case: touch /var/cache/mod_pagespeed/cache.flush)

That's it. The cache was reset.

就是这样。缓存已重置。

回答by jsmean

To disable complete module, try to have the following code in your .htaccess file

要禁用完整模块,请尝试在 .htaccess 文件中包含以下代码

<IfModule pagespeed_module>
ModPagespeed off
</IfModule>

回答by oschaaf

To make mod_pagespeed reflect changes to assets immediately, you can configure LoadFromFile: https://developers.google.com/speed/pagespeed/module/domains#ModPagespeedLoadFromFile

要使 mod_pagespeed 立即反映对资产的更改,您可以配置 LoadFromFile:https: //developers.google.com/speed/pagespeed/module/domains#ModPagespeedLoadFromFile

This will not work for css/js/images served from virtual handlers, but any changes to static content will be re-optimized immediately. In addition to that, optimization itself will usually be finished a lot faster because loading assets from disk is cheaper then fetching them from http(s).

这不适用于从虚拟处理程序提供的 css/js/images,但对静态内容的任何更改都将立即重新优化。除此之外,优化本身通常会更快地完成,因为从磁盘加载资源比从 http(s) 获取资源更便宜。

回答by Simon

GoDaddy Cloud Bitnami Config

GoDaddy 云 Bitnami 配置

/stack/apache2/conf/nano pagespeed.conf

/stack/apache2/conf/nano pagespeed.conf

Turn Off

关掉

回答by johnhenrygaspay

If you're using a W3C Total Cache plugin on WordPress you can try that to deactivate and view the file via inspect mode and always clear cache for the changes.

如果您在 WordPress 上使用 W3C Total Cache 插件,您可以尝试通过检查模式停用和查看文件,并始终清除缓存以进行更改。

回答by Jon Holland

Just as an aside, on this old post, I wrote a PHP script to delete the contents of the pagespeed cache folders (which I placed within the var/www/html area) and added a button to the Magento admin cache control page to call it. This way, whenever the Magento cache needs clearing I can also hit the button to clear the pagespeed cache. The script can be IP and admin restricted. This saves a lot of messing about. You could use a recursive delete folder function like this (careful with your paths!!:) ):

顺便说一句,在这篇旧帖子中,我编写了一个 PHP 脚本来删除 pagespeed 缓存文件夹(我放置在 var/www/html 区域内)的内容,并在 Magento 管理缓存控制页面添加了一个按钮以调用它。这样,每当 Magento 缓存需要清除时,我也可以点击按钮清除页面速度缓存。该脚本可以是 IP 和管理员限制。这样可以省去很多麻烦。您可以使用这样的递归删除文件夹功能(小心您的路径!!:)):

function fullDeleteFolder($dir) { 
  echo "Remove: ".$dir."<br>";
    if (is_dir($dir)) { 
        $objects = scandir($dir); 
        foreach ($objects as $object) { 
            if ($object != "." && $object != "..") { 
                if (is_dir($dir."/".$object)){
                    fullDeleteFolder($dir."/".$object);
                }else{
                    unlink($dir."/".$object); 
                }
            }
            }           
        rmdir($dir); 
    }
}

$location = "[some-location]/mpcache/mod_pagespeed";    
fullDeleteFolder($location);
//might also want to do this for the 'media/css_secure' folder too, if your site is on https
echo "Finished.";

回答by Phil LaNasa

Another thing you can do is leave *mod_pagespeed* out of your ssl.conffile. This way, you can access your site via https for development.

您可以做的另一件事是将 *mod_pagespeed* 排除在ssl.conf文件之外。这样,您就可以通过 https 访问您的站点进行开发。

Kind of a hack, I know, but it's handy in some cases where you need to make very quick changes.

我知道,这有点像 hack,但在某些需要快速更改的情况下它很方便。