Кешируем статику и уменьшаем нагрузку на сервер

Ввиду того что я в последнее время стал очень ленивым и как следстве редко редактирую файлы движка, то решил закешировать все что можно и немного разгрузить сервер. Изображения, флеш, иконки, скрипты, стили — все в кеш В htaccess перед Rewrite engine On добавляем

<IfModule mod_expires.c>
	ExpiresActive on

	ExpiresDefault "access plus 1 month"

	# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
	ExpiresByType text/cache-manifest "access plus 0 seconds"

	# html
	ExpiresByType text/html "access plus 0 seconds"

	# XML
	ExpiresByType text/xml "access plus 0 seconds"
	ExpiresByType application/xml "access plus 0 seconds"

	# RSS
	ExpiresByType application/rss+xml "access plus 1 hour"

	# Favicon
	ExpiresByType image/x-icon "access plus 1 week"

	# Картинки
	ExpiresByType image/gif "access plus 1 month"
	ExpiresByType image/png "access plus 1 month"
	ExpiresByType image/jpeg "access plus 1 month"
	ExpiresByType image/jpg "access plus 1 month"

	# HTC файлы  (например css3pie)
	ExpiresByType text/x-component "access plus 1 month"

	# Нестандартные шрифты сайта
	ExpiresByType application/x-font-ttf "access plus 1 month"
	ExpiresByType font/opentype "access plus 1 month"
	ExpiresByType application/x-font-woff "access plus 1 month"
	ExpiresByType image/svg+xml "access plus 1 month"
	ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
	
# CSS и javascript
	ExpiresByType text/css "access plus 1 year"
	ExpiresByType application/javascript "access plus 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>
	# 1 день
	<filesMatch "\.(html|htm|php)$">
	Header set Cache-Control "max-age=172800, private, must-revalidate"
	</filesMatch>
</ifModule>

<IfModule mod_setenvif.c>
	#Эта конструкция для говнобраузера
	#Запрет отдачи HTTP-заголовков Vary
	BrowserMatch "MSIE" force-no-vary
	BrowserMatch "Mozilla/4.[0-9]{2}" force-no-vary
</IfModule>
Обновлено: 08/03/2016 — 23:13

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *