Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aktaumag/2894ce01acb8e741a797824ae683706e to your computer and use it in GitHub Desktop.
Save aktaumag/2894ce01acb8e741a797824ae683706e to your computer and use it in GitHub Desktop.
Кеш браузера на год и сжатие текста gzip, deflate или brotli
Кеш браузера на год и сжатие текста gzip, deflate или brotli
@aktaumag
Copy link
Author

aktaumag commented Apr 10, 2023

в .htaccess

<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf font/opentype font/otf font/ttf
</ifModule>

### WebSEO.kz Michael Nossov add: Добавил код для настройки кеширования
### ОКАЗЫВАЕТСЯ правила настройки кеширования не работают на виртуальном хостинге TimeWeb
###Кэширование с помощью модуля mod_headers - начало
#<ifModule mod_headers.c>
#    Header always set Strict-Transport-Security "max-age=31536000" env=HTTPS
##    #кэшировать html и htm файлы на один день
##    <FilesMatch "\.(html|htm)$">
##        Header set Cache-Control "max-age=31536000"
##        Header append Vary: Accept-Encoding
##    </FilesMatch>
##    #кэшировать css, javascript и текстовые файлы на одну неделю
##    <FilesMatch "\.(js|css|txt)$">
##        Header set Cache-Control "max-age=31536000"
##        Header append Vary: Accept-Encoding
##    </FilesMatch>
##    #кэшировать флэш и изображения на месяц
##    <FilesMatch "\.(flv|swf|ico|gif|jpg|jpeg|png|webp|woff|woff2)$">
##        Header set Cache-Control "max-age=31536000, public"
##        Header append Vary: Accept-Encoding
##    </FilesMatch>
##    #отключить кэширование
##    <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
##        Header unset Cache-Control
##    </FilesMatch>
#</ifModule>
###Кэширование с помощью модуля mod_headers - конец
### WebSEO.kz Michael Nossov add: Добавил код для настройки кеширования
###Кэширование с помощью модуля mod_expires - начало
#<ifModule mod_expires.c>
#    ExpiresActive On
#    #по умолчанию кеш в 5 секунд
#    ExpiresDefault "access plus 31536000 seconds"
#    #кэшировать флэш и изображения на месяц
#    ExpiresByType image/x-icon "access plus 31536000 seconds"
#    ExpiresByType image/jpeg "access plus 31536000 seconds"
#    ExpiresByType image/png "access plus 31536000 seconds"
#    ExpiresByType image/gif "access plus 31536000 seconds"
#    ExpiresByType image/webp "access plus 31536000 seconds"
#    #кэшировать css, javascript и текстовые файлы на одну неделю
#    ExpiresByType text/css "access plus 31536000 seconds"
#    ExpiresByType text/javascript "access plus 31536000 seconds"
#    ExpiresByType application/javascript "access plus 31536000 seconds"
#    ExpiresByType application/x-javascript "access plus 31536000 seconds"
#    #кэшировать html и htm файлы на один день
#    ExpiresByType text/html "access plus 31536000 seconds"
#    #кэшировать xml файлы на десять минут
#    ExpiresByType application/xhtml+xml "access plus 31536000 seconds"
#</ifModule>
###Кэширование с помощью модуля mod_expires - конец

Часто не добавлено сжатие для шрифтов, ну а если json используется, то вообще редко встретишь.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment