This article will introduce you to the php control page browser cache and the gzip transfer page method. I hope this code will be helpful to you and those who do not have Server permissions can.
This article will introduce you to the php control page browser cache and the gzip transfer page method. I hope this code will be helpful to you, if you do not have the server permission, you can transfer the gzip page of the server.
The gzip transfer page of the php instance can be used for static resources and html pages. the modification is also applicable to other languages. the code is as follows:
- // Cache Expiration Time (Cache-Control, http1.1), recommended
- $ Secs = 0; // second
- Header ("Cache-Control: s-maxage = $ secs, max-age = $ secs, must-revalidate, proxy-revalidate ");
- // The 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 permissions, refer to apache to enable gzip transfer.
1. find your httpd. conf file and open the file as follows:
LoadModule deflate_module modules/mod_deflate.so
Go to the previous #, because the mod_deflate.so module is disabled by default.
2. put the current code at the end of your httpd. conf file. the code is as follows:
- SetOutputFilter DEFLATE
- DeflateCompressionLevel 5
- AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript
-
Restart apache and then KO.
Enable gzip page transmission in iis
1. open the Internet Information Service (IIS) manager, right-click "website"-"" properties ", and select" service ". In the "HTTP compression" box, select "compressing application files" and "compressing static files", and set "temporary directory" and "maximum temporary directory limit" as needed ";
2. in the Internet Information Service (IIS) manager, right-click "Web service extension"-"add a new Web service extension ...", Enter the extension "HTTP Compression" in the "new Web service extension" box and add the "required file" as C: WINDOWSsystem32inetsrvgzip. dll, the Windows system directory may vary depending on your installation, select "set extension status to allow ";
3. open C: WindowsSystem32inetsrvMetaBase in the text editor. xml (backup is recommended), locate Location = "/LM/W3SVC/Filters/Compression/gzip to set gzip Compression, locate Location = "/LM/W3SVC/Filters/Compression/deflate" to set deflate Compression. the above two nodes are next to each other and the set attributes are the same.
To compress dynamic files, set HcDoDynamicCompression to "TRUE", and add the dynamic file suffix to HcScriptFileExtensions, such as aspx;
To compress static files, set HcDoStaticCompression and HcDoOnDemandCompression to "TRUE",
Add the extension names of the static files to be compressed in HcFileExtensions, such as xml and css. HcDynamicCompressionLevel and HcOnDemandCompLevel indicate the compression ratio. The value ranges from 0 to 10. the default value is 0.
HcDynamicCompressionLevel attribute description: HcDynamicCompressionLevel Metabase Property
HcOnDemandCompLevel attribute description: HcOnDemandCompLevel Metabase Property
Note:We recommend that you set these two attribute values to 9, which is cost-effective.
Note:
1. stop IIS before editing MetaBase. xml. you can use net stop iisadmin
2. after the modification is complete, enable the iisadmin service and execute the iisreset command.
SEO testing
Whether compression has an impact on SEO. after testing, it can still be well recorded after being enabled.
For more information about the SEO impact, see the following articles.
The specific efficiency issues will be monitored for further research.