Как улучшить индекс pagespeed/скорость сайта. Эффективное использование кеша для статических объектов
Если проверка скорости сайта на pagespeed показывает…
![class=](https://hqline.ru/wp-content/uploads/2023/01/image-10-8.png)
![class=](https://hqline.ru/wp-content/uploads/2023/01/image-8-8.png)
, то для устранения проблемы можно воспользоваться правилами htaccess, чтобы включить кеширование статических объектов
<IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access 7 days" ExpiresByType application/javascript "access plus 1 year" ExpiresByType text/javascript "access plus 1 year" ExpiresByType text/css "access plus 1 year" ExpiresByType text/x-javascript "access 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType image/jpg "access plus 1 year" ExpiresByType image/x-icon "access 1 year" ExpiresByType application/x-shockwave-flash "access 1 year" </IfModule> # Cache-Control <ifModule mod_headers.c> # 30 дней <filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|swf)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> # 30 дней <filesMatch ".(css|js)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> # 2 дня <filesMatch ".(xml|txt)$"> Header set Cache-Control "max-age=172800, public, must-revalidate" </filesMatch>
После установки правил в результате получим совсем другую картину
![class=](https://hqline.ru/wp-content/uploads/2023/01/image-11-8.png)
![class=](https://hqline.ru/wp-content/uploads/2023/01/image-9-9.png)