• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • Support for BIND DNS has been removed from Plesk for Windows due to security and maintenance risks.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS.

NGINX does not GZIP scripts with version parameters

Xavier1234

New Pleskian
Hi,

I'm using latest plesk with ubuntu 12.04, apache and nginx, gzip is enabled and working fine, except for JS and CSS files wich have version parameters in the URI, for example :
http://domain.com/wp-content/plugins/sitepress-multilingual-cms/res/css/language-selector.css?v=3.1.9.7

here is my conf in /etc/nginx/conf.d/gzip.conf :
Code:
gzip         on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_proxied any;
gzip_types   text/plain text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary    on;

Gzip is working fine for every other ressources loaded
I know i can strip these ?ver= using PHP, but if nginx could just enqueue them properly as they are, i would be the happiest man, thank you!

Thank you
 
Hi Xavier1234,

how do you check, if "...v=3.1.9.7" is being compressed or not? As a matter of fact, the additional string should not be a reason for nginx to not compress such files. Please make sure, that apache AND nginx have the same corresponding gzip - settings.
 
Hi Xavier1234,

how do you check, if "...v=3.1.9.7" is being compressed or not?
Hello and thank you, i check using http://gtmetrix.com/ gtmetrics tells me that all files ending with a parameter ?v=x.x.x or ?ver=x.x.x are not compressed, if i strip the parameter using php, they end up being compressed
Please make sure, that apache AND nginx have the same corresponding gzip - settings.
Apache:
Code:
SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
    SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
</IfModule>
and
here is my conf in /etc/nginx/conf.d/gzip.conf :
Code:
gzip         on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_proxied any;
gzip_types   text/plain text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml;
gzip_vary    on;
 
Hi Xavier1234,

if you use wordpress, you might wish to use the additional code in your theme - specific - functions.php:

Code:
        function _remove_script_version( $src ){
            $parts = explode( '?', $src );
            return $parts[0];
        }
        add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
        add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
 
Back
Top