V
V
Vitaly Frolov2017-10-11 15:12:25
Apache HTTP Server
Vitaly Frolov, 2017-10-11 15:12:25

Website optimization, enable compression and caching on Centos server?

In general, the essence is this:
there is a site that lies on the Centos server. You need to enable compression and caching.
Added this code to httacess

### Сжать ответ сервера для перечисленных MIME типов
<ifModule mod_deflate.c>
  <IfModule mod_filter.c>
      AddOutputFilterByType DEFLATE text/plain text/html
      AddOutputFilterByType DEFLATE text/css
      AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
      AddOutputFilterByType DEFLATE text/xml application/xml application/xhtml+xml application/rss+xml
      AddOutputFilterByType DEFLATE application/json
      AddOutputFilterByType DEFLATE application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon
  </ifModule>
</ifModule>


### Способ #1
### Подсказать браузеру схему кеширования через заголовки в ответе сервера
<ifModule mod_headers.c>
    # 43200 - день, 604800 - неделя, 2592000 - месяц
    <FilesMatch "\.(html|js|css)$">
  Header set Cache-Control "max-age=2592000"
        #Header unset Last-Modified
    </FilesMatch>
    <Files *.txt>
  Header add Cache-Control "max-age=43200"
    </Files>
    <FilesMatch "\.(flv|swf|ico|gif|jpg|jpeg|png)$">
  Header set Cache-Control "max-age=2592000"
    </FilesMatch>
    <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
  # отключить кэширование
  Header unset Cache-Control
    </FilesMatch>
</IfModule>

### Способ #2
### Подсказать браузеру схему кеширования через заголовки в ответе сервера
<IfModule mod_expires.c>
    # Enable expires
    ExpiresActive On
    
    # Default a cache expiration
    ExpiresDefault "access plus 10 month"
    
    # Images
    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"
    
    # CSS, JavaScript
    ExpiresByType text/css                  "access plus 1 year"
    ExpiresByType application/javascript    "access plus 1 year"
    ExpiresByType text/javascript           "access plus 1 year"
</IfModule>


### Удалить заголовок ETag (иначе есть проблемы с кешированием при включенном сжатии)
<IfModule mod_headers.c>
    Header unset ETag
</IfModule>
FileETag None

It did not help, judging by Google page speed, although it shows that gzip is enabled on other resources.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question