Professional Documents
Culture Documents
According to Google's PageSpeed Insights Rules, there are 2 main parts to optimize page load speed.
Ref: https://developers.google.com/speed/docs/insights/rules?hl=en
CSS Please keep in mind that for this to improve your loading time, you must optimize CSS delivery.
JS By default all JavaScript is parser blocking.
The browser must pause to wait for the script to be fetched from disk, cache, or a remote server,
which can add tens to thousands of milliseconds of delay to the critical rendering path
You should avoid and minimize the use of blocking JavaScript, especially external scripts that must be fetched before they can be executed.
In short, you should follow these 10 rules of optimization to speed up page rendering:
We CARE: - All external JS files in target page (except async request such as gtm.js, analytics.js or js files from social widgets)
- All external CSS files in target page (except css files which are loaded after browser's load event)
- All external open font files in target page (only most important one, such as fontawesome icons)
We DON'T CARE: - All external widget files (Social widgets, Twitter iframes, Facebook scripts, Google Ads etc...)
- All files that are loaded AFTER the load event (the blue line in below graphic)
1
TODO
Example:
For CSS <link rel="preload" href="used-later.css" as="style">
For JS <link rel="preload" href="used-later-javascript.js" as="script">
Notice:
- Should not put too much <link rel="preload"> tags, putting under 20 tags is recommended
- The file path must be the same path with the file is used in the page (include URL parameters after '?' sign)
E.g: https://img.webike.net/css/header_nossl.css?v=2.0
↓
<link rel="preload" href="https://img.webike.net/css/header_nossl.css?v=2.0" as="style">
We CARE: - All external domains that the resources in the page come from
We DON'T CARE: - All files that are loaded AFTER the load event
We can use webpagetest.org site to check all domains used in a web page. Like the graphic below:
2
TODO
Example:
<link rel="dns-prefetch" href="https://img.webike.net">
<link rel="preconnect" href="https://img.webike.net" crossorigin="anonymous">
Notice:
- Define both preconnect and dns-prefetch tags for each domain
- We do not need to preconnect to the same domain of the page because it has been already established
- Keep amount of preconnect and dns-prefetch under 10 domains
We CARE: - If your HTML loads third-party widgets before it loads the main content, change the order to load the main content first
- If your site uses a two-column design with a navigation sidebar and an article, consider loading the main column before the sidebar
- Consider using CSS instead of images where possible
Notice:
This step takes time to re-structure, fix CSS and JS for speed optimization, please test carefully before release.
3
TODO
We DON'T CARE: - All external CSS files (Social widgets, Twitter iframes, Facebook scripts, Google Ads etc...)
- All CSS files that are loaded AFTER the load event
- Reduce slow selector and properties. Some properties are slower to render than others
NG *, ::before, ::after {
box-shadow: 5px 5px 5px rgba(0,0,0,0.5);
}
Slow properties:
border-radius
box-shadow
opacity
transform
filter
position: fixed
- Reduce CSS3 animations. If use, only apply animation to the elements which will animate.
- Prefer using SVG graphic rather than JPG and PNG bitmaps
OK .mysvgbackground {
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 600"><circle cx="400" cy="300"
}
- Avoid base64 bitmap images because it does have benefit of using browser cache
4
TODO
NG .myimg {
background-image: url('data:image/png;base64,ABCDEFetc+etc+etc');
}
We DON'T CARE: - All external JS files (Social widgets, Twitter iframes, Facebook scripts, Google Ads etc...)
- All JS files that are loaded AFTER the load event
We DON'T CARE: - All files that are loaded AFTER the load event
We CARE: - All iframe in the page (including Youtube, Vimeo, Twitter widgets, Facebook widgets, Advertisement)
- All <embed> tags
What we DO:
- Use lazyload technique for all iframe, embed tags in the page
- Only initialize lazy load after browser's load event for the best result
We CARE: - All inline <style> tags which contain background url() attribute
- All inline style attributes which contain background url() attribute
5
TODO
What we DO:
- Apply this technique to lazyload style which contains background images
NG <div data-u="loading" style="
position: absolute;
top: 0px; left: 0px;
background: url('jp_statics/gfs/nossl_css/jssor/loading.gif') no-repeat 50% 50%;
background-color: rgba(0, 0, 0, 0.7);
">
...
</div>
Fix Using javascript to apply background image for elements when the load event has been fired
Notice:
- If the background image is small, preload it using the rule 01 (<link rel="preload">)
What we DO:
- Add a <meta viewport> tag if missing
OK <meta name="viewport" content="width=device-width,initial-scale=1">
- Add a <meta charset> tag if missing
OK <meta charset="UTF-8">
<meta charset="Shift_JIS">
- Add missing lang attribute in <html> tag
OK <html lang=”ja”>