Free Call
+95 9 450043919

Gzip compression ကိုအသုံးပြုခြင်း

Gzip compression ကိုအသုံးပြုခြင်း

Gzip compression
Apache Server တွေမှာ အရင်က mod_gzip ဆိုပြီး နောက်ပိုင်းတော့ mod_deflate module အဖြစ် အစားထိုးလာခဲ့ပါပြီ။ Client က Request လုပ်လိုက်တဲ့ Data တွေကို Server ကနေ Compressed (zip ချုံ့) ပြီးပြန်ပို့တာပါ။ ကျွန်တော်တို့ File အရမ်းကြီးလွန်းရင် zip လုပ်ပြီး Portable Drive တွေထဲ ထည့်သယ်သွားသလိုပေါ့။
ဥပမာ – Gzip မလုပ်ထားတဲ့ Website တစ်ခုရဲ့ Total Page Size ကိုကြည့်မယ်ဆိုရင် 3 MB လောက်ရှိတယ်ဆိုပါစို့ Gzip လုပ်လိုက်ရင် 1 MB အောက်လောက်ပဲ ရှိပါတော့မယ်။ စဉ်းစားကြည့်ပေါ့ 3 MB ရှိတဲ့ Page Loading နဲ့ 1 MB လောက်ရှိတဲ့ Page Loading တို့ရဲ့ အမြန်နှုန်းကွာခြားချက်ကို။ ဒါကြောင့် မိမိအနေနဲ့ Website တစ်ခု လွင့်တင်ပြီးပြီဆိုရင် Gzip လုပ်ထားဖို့တော့ လိုပါတယ်။ အကယ်၍ မိမိရဲ့ site gzip လုပ်မလုပ်ဆိုတာ အွန်လိုင်း site တွေကနေလည်း အလွယ်တကူ စစ်ကြည့်နိုင်ပါတယ်။

Gzip compression
Webserver ဘက်ကနေ Configure လုပ်ပေးရမှာတွေရှိပါတယ်။ Client ဘက်ကနေ .htaccess ဖြင့် Gzip လုပ်နိုင်ပေမယ့် Server မှာ ၄င်း module မထည့်ထားရင် သုံးလို့ရမှာမဟုတ်ပါဘူး။

Webserver မှာ configure ချတာကတော့ WHM/cPanel သုံးတဲ့သူတွေအနေနဲ့ EasyApache > Server Modules > Apache Modules အတွင်းကနေ mod_deflate module ကို enable လုပ်ထားပေးရပါလိမ့်မယ်။ အကယ်၍ အသုံးပြုသူ User Account တွေအတွက် Enable လုပ်ထားချင်တယ်ဆိုရင်တော့ Apache Configuration Pre VirtualHost ကိုပြင်ပေးရပါလိမ့်မယ်။
Home » Service Configuration » Apache Configuration » Include Editor

<IfModule mod_deflate.c>
	# Insert filter
	SetOutputFilter DEFLATE
	<IfModule mod_setenvif.c>
		# Netscape 4.x has some problems…
		BrowserMatch ^Mozilla/4 gzip-only-text/html

		# Netscape 4.06-4.08 have some more problems
		BrowserMatch ^Mozilla/4.0[678] no-gzip

		# MSIE masquerades as Netscape, but it is fine
		BrowserMatch bMSIE !no-gzip !gzip-only-text/html

		# Don’t compress images
		SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
	</IfModule>

	<IfModule mod_headers.c>
		# Make sure proxies don’t deliver the wrong content
		Header append Vary User-Agent env=!dont-vary
	</IfModule>
</IfModule>

Restart Apache ချပါ။

Apache Webserver တွေအတွက်ကတော့ .htaccess ကိုအသုံးပြုနိုင်ပါတယ်။

<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 handler ^cgi-script$
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>

NGINX Webservers တွေအတွက်ကတော့ config မှာ

gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Disable for IE < 6 because there are some known problems
gzip_disable "MSIE [1-6].(?!.*SV1)";

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;

ထည့်ပေးရပါလိမ့်မယ်။

WHM/cPanel တွေမှာ gzip အတွက် mod_deflate module ကြိုတင်ထည့်ထားပေးပြီးသားပါ။ အကယ်၍ မိမိ site ရဲ့ gzip လုပ်ထားခြင်း မထားခြင်းကိုသိလိုလျှင် https://varvy.com/tools/gzip/ မှာလည်း စစ်ကြည့်နိုင်ပါတယ်။