PHP Instance gzip Transfer page
The code is as follows |
Copy Code |
Can be used for static resources and HTML pages, which are also suitable for other languages Cache Expiration Time (Cache-control, http1.1), recommended for use $secs = 0; Seconds Header ("Cache-control:s-maxage= $secs, max-age= $secs, Must-revalidate, proxy-revalidate"); Cache expiration Time is 24 hours (Expires) $offset = 3600 * 24; $expire = "Expires:". Gmdate ("D, D M Y h:i:s", Time () + $offset). "GMT"; Header ($expire); Last-modified, Last modified time $gmt _mtime = gmdate (' d, D M Y h:i:s ', Time ()). ' GMT '; Header ("last-modified:"). $gmt _mtime); Enable gzip compression Ob_start (); ... your PHP code ... ... your PHP code ... ... your PHP code ... Header (' Content-length: '. Ob_get_length ()); Ob_end_flush (); |
If you have server privileges, refer to Apache to enable gzip transfer
One, find your httpd.conf file, open to find the following
LoadModule Deflate_module modules/mod_deflate.so
Put the front of the # to go, because the Mod_deflate.so module by default is off, okay, next
Second, put the face code in your httpd.conf file on the last side of the good.
The code is as follows |
Copy Code |
<ifmodule mod_deflate.c> Setoutputfilter DEFLATE Deflatecompressionlevel 5 Addoutputfilterbytype DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript </IfModule> |
Restart your Apache and you'll be KO.
IIS opens gzip page transfer
1. Open Internet Information Services (IIS) Manager, right-click Web site-Properties, and select Services. In the HTTP Compression box, select Compress application files and compress static files, and set the maximum limit for temporary directories and temporary directories as needed;
2. In Internet Information Services (IIS) Manager, right-click "Web Service Extensions"-"Add a new Web service extension ...", and in the new Web service Extension box, enter the extension "HTTP Compression" to add "required files" Is C:windowssystem32inetsrvgzip.dll, where the Windows system directory may be different depending on your installation, and select "Set extended status to allow";
3. Use a text editor to open C:windowssystem32inetsrvmetabase.xml (recommended to back up first),
Find location = "/lm/w3svc/filters/compression/gzip used to set gzip compression,
Find location = "/lm/w3svc/filters/compression/deflate" to set deflate compression. The top two nodes are next to each other. And the properties set are the same.
If you need to compress a dynamic file, set HcDoDynamicCompression to TRUE.
And in HcScriptFileExtensions, add the dynamic file suffix name, such as ASPX, that you want to compress;
If you need to compress a static file, set HcDoStaticCompression and HcDoOnDemandCompression to "TRUE".
And in hcfileextensions to add you need to compress the static file suffix name, such as XML, CSS, etc.;
HcDynamicCompressionLevel and HcOnDemandCompLevel indicate the desired compression rate, with a value of 0-10 and a default of 0.
HcDynamicCompressionLevel attribute Description: HcDynamicCompressionLevel Metabase Property
HcOnDemandCompLevel attribute Description: HcOnDemandCompLevel Metabase Property
Description: These two property values are generally recommended to set to 9, with the best price/performance.
Attention
1. You need to stop IIS before editing MetaBase.xml, you can use net stop IISAdmin
2. Open the IISADMIN service after the modification is completed and execute the IISRESET command
About the SEO test
Whether the compression has an impact on SEO, after testing, open can still be very good included.
About the impact of SEO research articles, you can also refer to the following several articles.
Specific efficiency issues that will continue to be monitored for research