我从谷歌收到了下一个通知:
example.com/assets/a3f4f38d/jquery.min.js (expiration not specified) example.com/css/main.css (expiration not specified)
example.com/css/swiper.min.css (expiration not specified)
example.com/img/clouds/cloud-portfolio_mob.png (не указан срок действия) example.com/img/clouds/min0.png (expiration not specified)
example.com/img/clouds/min1.png (expiration not specified) example.com/img/clouds/min2.png (expiration not specified)
example.com/img/heroes/A.jpg (expiration not specified) example.com/img/heroes/B.jpg (expiration not specified)
example.com/img/heroes/C.jpg (expiration not specified) example.com/img/icons/Dot.gif (expiration not specified) example.com/img/icons/menuSm_min.png (expiration not specified)
example.com/img/icons/red-heart-border_min.png (не указан срок действия) example.com/img/icons/red-heart_min.png (не указан срок действия) example.com/img/loader/Loader-Advanced.gif (не указан срок действия)
example.com/img/logo/t.svg (expiration not specified) example.com/img/main_background/bg_mob.jpg (expiration not specified)
为了解决这个问题,我发现了下一个行为:
public function behaviors()
{
return [
[
'class' => 'yiifiltersHttpCache',
'only' => ['index'],
'lastModified' => function ($action, $params) {
// $q = new yiidbQuery();
return time() + 3600;
// return $q->from('users')->max('updated_at');
},
'sessionCacheLimiter' => 'public',
// 'etagSeed' => function ($action, $params) {
// return // generate ETag seed here
// }
],
];
}
在此之后,main文档(不适用于所有请求,仅适用于/)会出现三个额外的标题:
Cache-Control:public, max-age=3600 Last-Modified:Fri, 13 May 2016 09:03:45 GMT Pragma:
Altughter集时间()+3600,上次修改等于数据标头
如何为所有请求而不是仅为设置/所以,据我所知,谷歌希望我设置ExpireHeader?
Expire进入web文件夹中的.htaccess:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
此外,在yii2中,您可以设置版本(查询字符串):
'components' => [
'assetManager' => [
'appendTimestamp' => true,
],
],
信息:http://www.yiiframework.com/doc-2.0/guide-structure-assets.html#cache-破坏
版本还是上次修改
下面是的深入解释:文件缓存:查询字符串与上次修改?