Jump to content

How can I compress js and css files via gzip?


Vladyslav Harbarchuk

Recommended Posts

Hi, guys. 

How can I enable Gzip compression in IPB 4? I've tested my forum in Google Page Speed and I found out that js and CSS file don't compress. 
I turn on gzip compression in Nginx, and it works fine for static files from my web-site. But it doesn't work for files from a forum. 

I guess it's because of parameters "?v=", but could you tell me please, how can I fix this?

Thanks you

5682629620908_ScreenShot2015-12-29at12.3

Link to comment
Share on other sites

39 minutes ago, Adlago said:

Use appropriate htaccess file.

What exactly do you mean? I'm not really good at mod.rewrite rules :(

Here is my .htaccess file

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico)(\?|$) /404error.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forum/index.php [L]

Redirect 301 /forum/register/ http://intermilano.ru/index.php?do=register
</IfModule>

 

40 minutes ago, Adlago said:

ACP - Customization - Themes - Edit your theme - Custom -> " Javascript include location : Just before </body> tag"

yeah, It's already enable.

Link to comment
Share on other sites

@Vladyslav HarbarchukTry this htaccess

FileETag None
<IfModule mod_deflate.c> 
<filesMatch ".(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
  </filesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 week"
ExpiresByType video/x-flv "access plus 1 week"
ExpiresByType application/pdf "access plus 1 week"
ExpiresByType text/xml "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
<Files 403.shtml>
order allow,deny
allow from all
</Files>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico)(\?|$) /404error.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forum/index.php [L]

Redirect 301 /forum/register/ http://intermilano.ru/index.php?do=register
</IfModule>

 

Link to comment
Share on other sites

Uhhh... something that I guess somebody doesn't realize... nginx does NOT use .htaccess - and from the original post, it looks like he's using nginx.
This works for me in nginx (it's standard CentMin Mod setup).  First three lines should be one line - appearently it wraps instead of extends in the code box.

You can put that in a standalone file and then do an include in your nginx vhost

 include /path/to/file/staticfiles.conf;

    location ~* \.(3gp|woff|woff2|ttf|eot|svg|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
	gzip_static off;
	#add_header Pragma public;
	add_header Cache-Control "public, must-revalidate, proxy-revalidate";
	access_log off;
	expires 30d;
	break;
        }

    location ~* \.(js)$ {
	#add_header Pragma public;
	add_header Cache-Control "public, must-revalidate, proxy-revalidate";
	access_log off;
	expires 30d;
	break;
        }

    location ~* \.(css)$ {
	#add_header Pragma public;
	add_header Cache-Control "public, must-revalidate, proxy-revalidate";
	access_log off;
	expires 30d;
	break;
        }

    location ~* \.(html|htm|txt)$ {
	#add_header Pragma public;
	add_header Cache-Control "public, must-revalidate, proxy-revalidate";
	access_log off;
	expires 1d;
	break;
        }

    location ~* \.(eot|svg|ttf|woff|woff2)$ {
	#add_header Pragma public;
	add_header Cache-Control "public, must-revalidate, proxy-revalidate";
	access_log off;
	expires 30d;
	break;
        }

 

Link to comment
Share on other sites

1 hour ago, Tracy Perry said:

Uhhh... something that I guess somebody doesn't realize... nginx does NOT use .htaccess - and from the original post, it looks like he's using nginx.
This works for me in nginx (it's standard CentMin Mod setup).  First three lines should be one line - appearently it wraps instead of extends in the code box.

You can put that in a standalone file and then do an include in your nginx vhost

Thanks. I think it doesn't work because I don't have this line in my config. The problem is solved now.

add_header Cache-Control "public, must-revalidate, proxy-revalidate";
Link to comment
Share on other sites

  • 11 months later...

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...