search
HomeWeb Front-endHTML Tutorial一次WEB前端优化尝试 - jerrylsxu

今天对自己做的项目中的一个设计器界面加载速度上进行了优化,因为页面在加载的时候,感觉有点慢。首先,我用firefox的yslow和chrome的pagespeed进行了测试,效果如下,分数有点不同,但是都是很低的。我其实主要在chrome下用pagespeed的提示进行优化的。

yslow优化前:

         

yslow优化后:

 

pagespeed优化前:

 

pagespeed优化后:

 

优化策略:

          1.tomcat配置启用gzip压缩  

          2.tomcat配置静态文件的过期时间

          3.css放页面上方

          4.javascript放页面下方

          5.css和js文件分别合并、压缩

 

tomcat启用gzip压缩

 

打开tomcat的conf目录下的server.xml文件,修改如下

 

  1. Connector port="80" protocol="HTTP/1.1"   
  2.            connectionTimeout="20000"   
  3.            redirectPort="8443" executor="tomcatThreadPool" URIEncoding="utf-8"   
  4.                        compression="on"   
  5.                        compressionMinSize="50" noCompressionUserAgents="gozilla, traviata"   
  6.                        compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" />  

 参考链接:http://blog.csdn.net/hbcui1984/article/details/5666327

 

 

tomcat配置静态文件过期时间

 

打开tomcat的conf目录下的web.xml文件,增加如下:

  1. filter>  
  2.        filter-name>ExpiresFilterfilter-name>  
  3.        filter-class>org.apache.catalina.filters.ExpiresFilterfilter-class>  
  4.        init-param>  
  5.           param-name>ExpiresByType imageparam-name>  
  6.           param-value>access plus 10 minutesparam-value>  
  7.        init-param>  
  8.        init-param>  
  9.           param-name>ExpiresByType text/cssparam-name>  
  10.           param-value>access plus 10 minutesparam-value>  
  11.        init-param>  
  12.        init-param>  
  13.           param-name>ExpiresByType application/javascriptparam-name>  
  14.           param-value>access plus 10 minutesparam-value>  
  15.        init-param>  
  16.     filter>  
  17.     filter-mapping>  
  18.        filter-name>ExpiresFilterfilter-name>  
  19.        url-pattern>/*url-pattern>  
  20.        dispatcher>REQUESTdispatcher>  
  21.     filter-mapping>  

过期时间:每次请求增加十分钟 

参考链接:https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/filters/ExpiresFilter.html

 

css文件合并压缩,js文件合并压缩

 

合并压缩使用grunt进行处理,简单方便

 

参考链接:http://www.cnblogs.com/snandy/archive/2013/03/11/2949177.html

http://www.cnblogs.com/snandy/archive/2013/05/20/3088613.html

 

总体来说,页面加载速度有所提升,因页面设计器中,各个组件的js和核心js加起来有30多个,我只针对这方面进行了压缩合并,其他引入的js插件都是使用的压缩后的;css方面我也只压缩合并的我自己增加的文件。图片方面没有把所有图片都合并到一个文件中,只有少部分icon整合了,这方面合并后应该还会有所提升。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!