A web Front-end optimization attempt and a WEB optimization Attempt
Today, I optimized the loading speed of a designer interface in my own project, because the page loading is a little slow. First of all, I tested yslow in firefox and pagespeed in chrome. The results are as follows. The scores are a little different, but they are all very low. In fact, I used pagespeed prompts in chrome for optimization.
Before yslow optimization:
After yslow optimization:
Before pagespeed optimization:
After pagespeed is optimized:
Optimization Strategy:
1. Enable gzip compression in tomcat configuration
2. tomcat configuration static file expiration time
3.put CSS at the top of the page
4. Place javascript below the page
5.css and js files are merged and compressed respectively.
Tomcat enables gzip Compression
Open the server. xml file in the conf directory of tomcat and modify the file as follows:
- <Connector port = "80" protocol = "HTTP/1.1"
- ConnectionTimeout = "20000"
- RedirectPort = "8443" executor = "tomcatThreadPool" URIEncoding = "UTF-8"
- Compression = "on"
- CompressionMinSize = "50" noCompressionUserAgents = "gozilla, traviata"
- CompressableMimeType = "text/html, text/xml, text/javascript, text/css, text/plain"/>
Reference: http://blog.csdn.net/hbcui1984/article/details/5666327
Tomcat static file expiration time
Open the web. xml file in the conf directory of tomcat and add the following:
- <Filter>
- <Filter-name> ExpiresFilter </filter-name>
- <Filter-class> org. apache. catalina. filters. ExpiresFilter </filter-class>
- <Init-param>
- <Param-name> ExpiresByType image </param-name>
- <Param-value> access plus 10 minutes </param-value>
- </Init-param>
- <Init-param>
- <Param-name> ExpiresByType text/css </param-name>
- <Param-value> access plus 10 minutes </param-value>
- </Init-param>
- <Init-param>
- <Param-name> ExpiresByType application/javascript </param-name>
- <Param-value> access plus 10 minutes </param-value>
- </Init-param>
- </Filter>
- <Filter-mapping>
- <Filter-name> ExpiresFilter </filter-name>
- <Url-pattern>/* </url-pattern>
- <Dispatcher> REQUEST </dispatcher>
- </Filter-mapping>
Expiration time: 10 minutes more for each request
Reference: https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/filters/ExpiresFilter.html
Css file merging and compression, js file merging and Compression
Merge compression and use grunt for processing, which is simple and convenient
Reference: http://www.cnblogs.com/snandy/archive/2013/03/11/2949177.html
Http://www.cnblogs.com/snandy/archive/2013/05/20/3088613.html
In general, the page loading speed is improved. As the page designer adds over 30 js and core js components, I only compress and merge these components, other introduced js plug-ins use compressed files. For css, I only compress and merge my own files. The image has not merged all the images into one file, but only a small number of icons have been integrated, which should be improved after the merge.