做个记录,摘自Front-End Performance Checklist 

HTML

  1. Minified HTML:The Front-End Checklist The HTML code is minified, comments, white spaces and new lines are removed from production files. 
  2. Remove unnecessary comments: The Front-End Checklist Ensure that comments are removed from your pages.
  3. Remove unnecessary attributes: The Front-End Checklist Type attributes like type="text/javascript" or type="text/css" are not required anymore and should be removed.
  4.  Place CSS tags always before JavaScript tags: The Front-End Checklist  Ensure that your CSS is always loaded before having JavaScript code.
  5. Minimize the number of iframes: The Front-End Checklist  Use iframes only if you don't have any other technical possibility. Try to avoid as much as you can iframes.

CSS

  1. Minification: The Front-End Checklist All CSS files are minified, comments, white spaces and new lines are removed from production files.
  2. Concatenation: The Front-End Checklist CSS files are concatenated in a single file (Not always valid for HTTP/2).(合并css,减少http请求,http2不必)
  3. Non-blocking: The Front-End Checklist CSS files need to be non-blocking to prevent the DOM from taking time to load.(css必须是非阻塞的)
    How:You need to add the rel attribute with the preload value and add as="style" on the <link> element
    <link rel="preload" href="a.css" as="style" onload="this.rel='stylesheet'">
    <noscript><link rel="stylesheet" href="a.css"></noscript>
  4. Length of CSS classes: The Front-End Checklist The length of your classes can have an (slight) impact on your HTML and CSS files (eventually).
  5. Unused CSS: The Front-End Checklist Remove unused CSS selectors.
  6. CSS Critical: The Front-End Checklist The CSS critical (or "above the fold") collects all the CSS used to render the visible portion of the page. It is embedded before your principal CSS call and between <style></style> in a single line (minified if possible).
    取出首屏渲染所必须的 critical CSS,以内联的方式写在 <style></style> 之中,然后异步加载剩余的 CSS 样式,这相当于离线加载剩余部分的 CSS 样式,然后在后台将其注入到页面中。
  7. Embedded or inline CSS: The Front-End Checklist Avoid using embed or inline CSS inside your <body> (Not valid for HTTP/2)
  8. Analyse stylesheets complexityThe Front-End Checklist Analyzing your stylesheets can help you to flag issues, redundancies and duplicate CSS selectors.
    分析样式表,去除冗余重复的代码

Fonts

  1. Webfont formats: The Front-End Checklist You are using WOFF2 on your web project or application.
  2.  Use preconnect to load your fonts faster: The Front-End Checklist
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  3. Webfont size: The Front-End Checklist Webfont sizes don't exceed 300kb (all variants included)
  4. Prevent Flash or Invisible Text: The Front-End Checklist Avoid transparent text until the Webfont is loaded

Images

  1. Images optimization: The Front-End Checklist Your images are optimized, compressed without direct impact to the end user.
  2. Images format: The Front-End Checklist Choose your image format appropriately.
  3. Use vector image vs raster/bitmap: The Front-End Checklist Prefer using vector image rather than bitmap images (when possible).
    矢量图像(SVG)往往比图像小,SVG的响应速度和比例都很好
  4. Images dimensions: The Front-End Checklist Set width and height attributes on <img> if the final rendered image size is known.
  5. Avoid using Base64 images: The Front-End Checklist You could eventually convert tiny images to base64 but it's actually not the best practice.
  6. Lazy loading: The Front-End Checklist Images are lazyloaded (A noscript fallback is always provided).
  7. Responsive images: The Front-End Checklist Ensure to serve images that are close to your display size.(srcset和picture了解一下

JavaScript

  1. JS Minification: The Front-End Checklist All JavaScript files are minified, comments, white spaces and new lines are removed from production files (still valid if using HTTP/2).
  2. No JavaScript inside: The Front-End Checklist (Only valid for website) Avoid having multiple JavaScript codes embedded in the middle of your body. Regroup your JavaScript code inside external files or eventually in the <head> or at the end of your page (before </body>).
  3. Non-blocking JavaScript: The Front-End Checklist JavaScript files are loaded asynchronously using async or deferred using defer attribute.
  4. Optimized and updated JS libraries: The Front-End Checklist All JavaScript libraries used in your project are necessary (prefer Vanilla JavaScript for simple functionalities), updated to their latest version and don't overwhelm your JavaScript with unnecessary methods.
  5. Check dependencies size limit: The Front-End Checklist Ensure to use wisely external libraries, most of the time, you can use a lighter library for a same functionality.(比如dayjs替代了momentjs)
  6. JavaScript Profiling: The Front-End Checklist Check for performance problems in your JavaScript files (and CSS too).

Server

  1. Page weight < 1500 KB (ideally < 500 KB): The Front-End Checklist Reduce the size of your page + resources as much as you can.
  2. Page load times < 3 seconds: The Front-End Checklist Reduce as much as possible your page load times to quickly deliver your content to your users.
  3. Time To First Byte < 1.3 seconds: The Front-End Checklist Reduce as much as you can the time your browser waits before receiving data.
  4. Cookie size: The Front-End Checklist If you are using cookies be sure each cookie doesn't exceed 4096 bytes(4kb) and your domain name doesn't have more than 20 cookies.
  5. Minimizing HTTP requests: The Front-End Checklist Always ensure that every file requested are essential for your website or application.
  6. Use a CDN to deliver your assets: The Front-End Checklist Use a CDN to deliver faster your content over the world.
  7. Serve files from the same protocol: The Front-End Checklist Avoid having your website using HTTPS and serve files coming from source using HTTP.
  8. Serve reachable files: The Front-End Checklist Avoid requesting unreachable files (404).
  9. Set HTTP cache headers properly: The Front-End Checklist Set HTTP headers to avoid expensive number of roundtrips between your browser and the server.
  10. GZIP / Brotli compression is enabled: The Front-End Checklist

相关文章:

  • 2021-06-12
  • 2022-12-23
  • 2021-06-27
  • 2022-02-17
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-25
  • 2021-12-04
  • 2021-12-30
  • 2021-08-28
  • 2021-11-14
  • 2021-09-06
  • 2022-01-09
相关资源
相似解决方案