V
V
Vadim2017-02-05 14:38:23
htaccess
Vadim, 2017-02-05 14:38:23

Do I correctly form the htaccess file for compression and caching?

1. The option is used by mod_deflate and mod_headers We
compress js css and html pages (pages generated by php):

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/x-font-woff # Нужно ли сюда добавлять файлы шрифтов (какие)?
  AddOutputFilterByType DEFLATE text/html
</IfModule>

Using browser cache:
<IfModule mod_headers.c>
  <FilesMatch "\.(js|css)$">
    Header set Cache-Control "max-age=43200"
  </FilesMatch>
  <FilesMatch "\.(ico|gif|jpg|jpeg|png)$">
    Header set Cache-Control "max-age=2592000"
  </FilesMatch>
</IfModule>

Do fonts also need to use the browser cache?
2. Variant of mod_gzip and mod_expires
I haven't quite figured out mod_gzip, is it possible to specify only js and css in mod_gzip_item_include file or not to use it at all?, and to specify types in mod_gzip_item_include mime? To be similar to mod_deflate.
To compress js css and html (pages generated by php).
<IfModule mod_gzip.c>
  mod_gzip_on         Yes
  mod_gzip_dechunk    Yes
  mod_gzip_item_include file		\.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include mime		^text\.*
  mod_gzip_item_include mime		^application/x-javascript.*
  mod_gzip_item_include mime		^application/x-font-woff.*
  mod_gzip_item_exclude mime	^image\.*
  mod_gzip_item_exclude rspheader	^Content-Encoding:.*gzip.*
</IfModule>

Using browser cache:
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 43200 seconds"
  ExpiresByType text/javascript "access plus 43200 seconds"
  ExpiresByType application/javascript "access plus 43200 seconds"
  ExpiresByType application/x-javascript "access plus 43200 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
</IfModule>

Is it mandatory to use the ExpiresDefault parameter?
For fonts, it will be enough: application/x-font-ttf, font/opentype, application/x-font-woff?
Is everything described for correct operation?
Do I need to remove ETag and Last-Modified?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2017-02-06
@ShVad

1)
- Not a font file is added, but the mime type of the corresponding file, example

AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype

- It's worth using the cache for fonts if the font is not standard and is included in a separate file
2)
- mod_gzip_item_include has the format
type can be: mime, handler, file, uri, reqheader, rspheader
if the regular expression worked, then there will be caching.
Use files or mime types or both - it depends on the task. As an example, you can generate js or css in the file site_com/style.php and in this case, mime will work (assuming css header is sent in the script), but file won't. In general, I think the idea is clear ..
No, not necessarily. ExpiresDefault = general setting; ExpiresByType = more configurable but overrides ExpiresDefault values.
Depends on the set of fonts you use, see answer to point 1
If you do not have balancing (several web servers for one site), then you do not need to delete it. Using these headers, the web server understands which version of the page is in the browser cache and, accordingly, either generates a new page (http 200) or tells it to use the cache (http 304).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question