Compression and caching for the site


If your hosting and all settings go through the file .htaccess, then you need to add the following lines to it

<IfModule mod_gzip.c> #gzip compression
	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_exclude mime		^image\.*
	mod_gzip_item_exclude rspheader	^Content-Encoding:.*gzip.*
</IfModule>

<ifModule mod_headers.c> #caching
	
	<FilesMatch "\.(html|htm)$">
		Header set Cache-Control "max-age=43200"
	</FilesMatch>
	
	<FilesMatch "\.(js|css|txt)$">
		Header set Cache-Control "max-age=604800"
	</FilesMatch>
	
	<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>

<ifModule mod_expires.c> #caching
	ExpiresActive On
	
	ExpiresDefault "access plus 5 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"
	ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
	ExpiresByType text/css "access plus 604800 seconds"
	ExpiresByType text/javascript "access plus 604800 seconds"
	ExpiresByType application/javascript "access plus 604800 seconds"
	ExpiresByType application/x-javascript "access plus 604800 seconds"
	ExpiresByType text/html "access plus 43200 seconds"
	ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>

If you have all the settings go through Apache + Nginx, then you should set the following in the Nginx domain configuration file

#turning on gzip
gzip_buffers 16 8k;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_types text/css text/plain text/json text/x-js text/javascript text/xml application/json application/x-javascript application/xml application/xml+rss application/javascript;
gzip_disable "msie6";
gzip_vary on;
gzip_http_version 1.0;

#and in line (example)
# Static files location
location ~* ^.+\.(jpg|jpeg|gif|swf|png|ico|mp3|css|zip|tgz|gz| rar|bz2|doc|xls|exe|pdf|dat|avi|ppt|txt|tar|mid|mi di|wav|bmp|rtf|wmv|mpeg|mpg|mp4|m4a|spx|ogx|ogv|og a|webm|weba|ogg|tbz|js)$ {
expires 7d; #add line
root /home/имя сервера/ваш домен.ru/docs;
access_log /home/имя сервера/ваш домен.ru/logs/access_log combined;
error_page 404 = @fallback;
log_not_found off;
# 1
accel_htaccess_switch on;
}

#and in the end should get such a file (depending on hosting)
server {
listen здесь ваш IP:80;
server_name ваш домен.ru www.ваш домен.ru;

location / {
proxy_pass http://здесь ваш IP:8080;
proxy_redirect http://ваш домен.ru:8080/ /;
proxy_redirect http://www.ваш домен.ru:8080/ /;


proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size 192m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 900;
proxy_read_timeout 900;

proxy_buffer_size 64k;
proxy_buffers 8 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
##############################################
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_types text/css text/plain text/json text/x-js text/javascript text/xml application/json application/x-javascript application/xml application/xml+rss application/javascript;
gzip_disable "msie6";
gzip_vary on;
gzip_http_version 1.0;
##############################################

# 1

# Static files location
location ~* ^.+\.(jpg|jpeg|gif|swf|png|ico|mp3|css|zip|tgz|gz| rar|bz2|doc|xls|exe|pdf|dat|avi|ppt|txt|tar|mid|mi di|wav|bmp|rtf|wmv|mpeg|mpg|mp4|m4a|spx|ogx|ogv|og a|webm|weba|ogg|tbz|js)$ {
##############################################
expires 7d;
##############################################
root /home/имя сервера/ваш домен.ru/docs;
access_log /home/имя сервера/ваш домен.ru/logs/access_log combined;
error_page 404 = @fallback;
log_not_found off;
# 1
accel_htaccess_switch on;
}

And the same should be in the Apache domain configuration file to register the following

<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
#find such a line and add a piece to it below
#########################################################
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_can_negotiate Yes
mod_gzip_update_static Yes
mod_gzip_static_suffix .gz
AddEncoding gzip .gz
mod_gzip_minimum_file_size 200
mod_gzip_maximum_file_size 5000000
mod_gzip_maximum_inmem_size 60000
mod_gzip_min_http 1000
mod_gzip_handle_methods GET POST
mod_gzip_temp_dir /tmp
mod_gzip_keep_workfiles No
mod_gzip_dechunk Yes
mod_gzip_send_vary On
mod_gzip_item_include file \.htm$
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.php$
mod_gzip_item_include file \.txt$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include file \.js$
mod_gzip_item_include file \.css$
mod_gzip_item_include file \.rdf$
mod_gzip_item_include file \.xml$
mod_gzip_item_include file \.rss$
mod_gzip_item_include mime ^application/x-httpd-php
mod_gzip_item_include mime ^application/x-javascript
mod_gzip_item_include mime ^application/javascript
mod_gzip_item_include mime ^text/css$
mod_gzip_item_include mime ^text/plain$
mod_gzip_item_include mime ^text/xml$
mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]"
</IfModule>
##############################################
</Directory>
</VirtualHost>

You can always check the result in PageSpeed




Connect

If you have any questions, want to get individual advice or you have an interesting offer, you can contact via the feedback form.

Or write to the email info@bobreod.ru





By submitting the form, you agree to our privacy policy