美文网首页
网站性能优化 の 前端构建要点

网站性能优化 の 前端构建要点

作者: michael_jia | 来源:发表于2016-08-13 20:21 被阅读53次
页面和模块
  • pages
  • imodules
部署到 cdn 的内容

├── images
├── iscripts
└── sass

PageSpeed Score
  1. Serve scaled images(大图当小图用,浪费!)
    Serving appropriately-sized images can save many bytes of data and improve the performance of your webpage, especially on low-powered (eg. mobile) devices.
  2. Leverage browser caching(用好 expires time示例Google speed insight
    Page load times can be significantly improved by asking visitors to save and reuse the files included in your website.
    • Reduces page load times for repeat visitors
    • Particularly effective on websites where users regularly re-visit the same areas of the website
    • Benefit-cost ratio: high;
    • Access needed;
  3. Minify JavaScript(压缩 JS,gulp 轻易做到)
    Compacting JavaScript code can save many bytes of data and speed up downloading, parsing, and execution time.
  4. Enable gzip compression
    Reduce the size of files sent from your server to increase the speed to which they are transferred to the browser
    • Reduce sizes of pages by up to 70%
    • Increase page speed
    • Cost-benefit ratio: high
    • Access needed to the .htaccess files or server administration files;
  5. Specify a Vary: Accept-Encoding header
    Bugs in some public proxies may lead to compressed versions of your resources being served to users that don't support compression. Specifying the Vary: Accept-Encoding header instructs the proxy to store both a compressed and uncompressed version of the resource.
  6. Inline small CSS
    Inlining small external CSS files can save the overhead of fetching these small files. A good alternative to inline CSS is to combine the external CSS files.
    对于小的 css 文件,要么直接将其内容放到 html 文件 style tag 中,要么合并到其他 css 文件中;
文件:src/imodules/www/common/InsertTop/main.html
<style type="text/css">@@include("../../dist/www/sass/reset.css")</style>
<style type="text/css">@@include("../../dist/www/sass/override.css")</style>
[Inline small CSS or combine the external CSS files](https://gtmetrix.com/reports/www.xxtao.com/6quO4cBl#)
YSlow Score
  • Compress components with gzip


    Compress components with gzip
页面指标(Page Details)
  • Page Load Time
  • Total Page Size
  • Requests
Responsive Web Design
jquery.shim.js 文件说明
  • http://www.example.com/global/iscripts/libs/jquery.shim.js
define(function () {
   return $; 
});
  • 目的
    这个文件主要是为了能正常引入依赖于 jQuery但又不支持 require 的第三方插件;
构建脚本

gulp --gulpfile=${siteroot}/gulpfile.js --site=www --use_cdn=1 --cdn=http://cdn.example.com/www/ release

  • style attribute( inline css), style tag, link css, 将 inline css 和 小 link css 文件改为 style tag 放到 html head 中;
CDN 示意
CDN 示意

相关文章

  • 网站性能优化 の 前端构建要点

    页面和模块 pages imodules 部署到 cdn 的内容 ├── images├── iscripts└─...

  • 前端面试必问及加分点---性能优化篇

    如何进行网站性能优化 你有用过哪些前端性能优化的方法? 谈谈性能优化问题 代码层面的优化 前端性能优化最佳实践

  • 前端性能优化(中)

    性能优化调研系列文章 《前端性能优化(上)》 《前端性能优化(中)》 《前端性能优化(下)》 《前端性能优化(上)...

  • 前端性能优化(下)

    性能优化调研系列文章 《前端性能优化(上)》 《前端性能优化(中)》 《前端性能优化(下)》 《前端性能优化(中)...

  • gulp

    1 gulp(自动化构建工具) 自动化构建 自动化构建:优化网站,提升网站性能,提高网站的代码,文件的优化处理 处...

  • 前端性能优化-开篇

    前端性能优化问题是每个前端需要掌握的技术。这篇文章从渲染优化、代码优化、资源优化、构建优化、传输加载优化、更多流行...

  • 前端性能优化(上)

    性能优化调研系列文章 《前端性能优化(上)》 《前端性能优化(中)》 《前端性能优化(下)》 为什么要进行前端性能...

  • 前端工程系列(二)

    前端工程与性能优化 首先,我们把雅虎14条优化原则,《高性能网站建设指南》以及《高性能网站建设进阶指南》中提到的优...

  • Web前端入门到实战:Web前端性能优化指南

    前端需要性能优化么? 性能优化一直以来都是前端工程领域中的一个重要部分。很多资料表明,网站应用的性能优化对于提高用...

  • web前端入门到实战:web前端性能优化指南

    前端需要性能优化么? 性能优化一直以来都是前端工程领域中的一个重要部分。很多资料表明,网站应用的性能优化对于提高用...

网友评论

      本文标题:网站性能优化 の 前端构建要点

      本文链接:https://www.haomeiwen.com/subject/jnoesttx.html