nginx minify css js html
awalnya iseng iseng bisa ga nginx nih nge minify js sama css nya on de felay
browsing dikit terus nemu git ini cekitdot
terus coba aja iseng okay ini setep by setep di centos ya
pertama karena tutor di sana make source maka di sini make aplikasi cpan make cpan krn di perl kalo di python biasanya pip atau easy_install okeh
1. install cpan
yum install cpan2. install modul perl buat nginx , ga perlu recompile
yum install nginx-module-perl.x86_64 #nginx repo if use epel its default install3. install deh paketan yg di butuhin di saa bilang pake XS
- HMTL => cpan install HTML::Packer
- CSS => cpan install CSS::Minifier::XS
- JS => cpan install JavaScript::Minifier::XS
load_module modules/ngx_http_perl_module.so;5. masukin di bagian html section ini (ikutin yg di github)
# minify6. selanjutnya ke bagian vhost section server kaya gini aja kalo pake gzip
perl_modules perl;
perl_require Minify.pm;
#minify
location ~ \.html$ { perl Minify::html_handler; expires 1y; add_header Cache-Control "public";}
location ~ \.css$ { perl Minify::css_handler; expires 1y; add_header Cache-Control "public";}
location ~ \.js$ { perl Minify::js_handler; expires 1y; add_header Cache-Control "public";}
6. yang ga pake gzip bisa ikutin yg di git
7. buat folder perl di /etc/nginx
location ~ \.html$ { perl Minify::html_handler; } location ~ \.js$ { perl Minify::js_handler; }
location ~ \.css$ { perl Minify::css_handler; }
mkdir /etc/nginx/perl; ln -s /etc/nginx/perl /usr/share/nginx/perl8. masuk ke folder itu terus download Minify.pm nya
cd /etc/nginx/perl; wget -c https://raw.githubusercontent.com/nginx-modules/nginx-minify/master/perl/Minify.pm9. test config dulu udah oke baru reload
nginx -t;
service nginx reload
trus buka deh webnya liat js/css di server sama di browser
#CMIIW
-good luck-
Comments
Post a Comment