on
Case Study on Web Performance Optimization
Recently, I completed Web perfomance optimization course from udacity to make things more clear in my head I analysed the webcompat.com. Webcompat is an add-on feature which helps in reporting any bug in a website.
As part of my analysis I consulted Lighthouse and Pagespeed Insights to measure performance of www.webcompat.com. I have noted down my findings based on each resource under a different heading. I have also included a list of fixes wherever it was possible for me to suggest an optimization. I have also made some changes and pushed on my own fork of the code to check how the resolution of some of the issues would look like.
Analysis of Lighthouse reports (Chrome web-dev tool)
Speed and related metrics
- First contentful paint (FCP) Marks the point after navigation when the browser renders first bit of content from DOM; for users it provides feedback that page is loading
- First meaningful paint (FMP) Marks the point when the most important (above-the-fold) content has been rendered and webfonts have loaded
- Time to interactive (TTI) Marks the time it takes for a page to become interactive, essentially – page has displayed useful content, event handlers are registered and page responds to user interaction
Large difference in FCP b/w Localhost and Live version On investigating the reports attached in the below comment, I see that there is a significant difference in FCP, FMP etc between localhost and live website. This is primarily because in the localhost the server doesn’t serve compressed test resources and doesn’t load minified JS. These two issues are not present in the live version of the site.
Issues in Live version
- An issue which is present in both the versions is the wait-time for render blocking resources.
-
Essentially components like google.fonts is preventing rendering of the website before this resource is fetched. Here I see that in layout.html we are linking – href= https://fonts.googleapis.com/css?family=Open+Sans:400,600|Source+Sans+Pro:300,400|PT+Mono To prevent this from blocking the rendering I used style element inside the body to load the fonts asynchronously. This helps with reducing the FCP, FMP and TTI by shaving off 0.4s on my localhost Lighthouse reports. One issue of this approach is that users might face FOUC (flash of unstyled content) while the fonts are still being loaded and can see a flicker. Some discussion on this: https://stackoverflow.com/questions/25230264/how-to-keep-css-from-render-blocking-my-website
I have created a new branch (LoadFontAsynch) on my fork and we can see the code changes at: https://github.com/14Richa/webcompat.com/tree/LoadFontAsynch
-
webcompat.min.css is also a render blocking resource according to the Lighthouse reports. In order to remove/reduce the rendering time we can use critical CSS (above the fold) in in-line fashion and load non-critical CSS asynchronously.
I have found a nice collection of resources which I can explore to address this issue: https://github.com/addyosmani/critical-path-css-tools
-
-
Unused CSS rules: webcompat.min.css has some unused rules which can be removed to further increase performance. [
Homepage
,Issuelist
,Issuepage
] On reading more on this I find some tools mentioned here would be helpful to find the unused css rules. Chrome web-dev tools also has a coverage option which checks for unused CSS/JS. More details: https://stackoverflow.com/questions/135657/how-to-identify-unused-css-definitions -
Making text visible during webfont load using font-display CSS feature. [
Homepage
,Issuelist
] We can use font-display attribute to change fallback logic or decrease block time of the fonts to display the fonts. More details: https://developers.google.com/web/updates/2016/02/font-display - Excessive DOM Size –> This issue is present in
Issueslist
page where it lists many issues in one page. This creates ~1100 nodes in the DOM tree. From what I understand, we can take a look at nodes which are displayed when the page loads and send only these nodes at first call, can render other nodes on user’s gesture. [Issuelist
]
Best Practices flaws
Some best practices flaws identified by Lighthouse
- Using http/2 for all resources
webcompat.com is currently hosted on nginx/1.1.19. We would need to upgrade it to nginx/1.9.5 atleast to be compatible with http/2. Since we already serve all our resources with https we satisfy the prerequisites there. In the comments I have added the protocol information for the resources served on the
homepage
. It should be easy to migrate the resources served using spydy to http/2 since http/2 was built on top of spydy. Here is a nginx tutorial on how to port/upgrade servers to http/2 - Twitter, Github links have target = “_blank”. This can impact performance in general because the linked url can execute a javascript on our page. I found though that linked url here were generally twitter and github links. I have created a branch where I added
rel=noopener
as suggested here. Performance benefits explained here. Finally here is a link to my code changes for review. Locally testing it improved the score in Lighthouse reports.
Analysis of Pagespeed Insights
Pagespeed is another google-supported tool used to understand which resources/best-practices can be checked into while understanding website performance. I have listed down somethings which I want to try to improve rendering performance of webcompat.com
- Browser caching for resources like needs-triage and google-analytics.
Homepage
Issuelist
- Minimizing all JS resources. For example: ga.js file is not fetched in a minified version.
Homepage
,Issuepage
- Removing render-blocking JS. issue-list.mi.js and wecompat.min.js are render blocking JS files. Maybe we can make an async call to these to improve performance.
Issuelist
,Issuepage
- All-above-the-fold content could not be rendered with one html response. We can try to organize the content in a different way so that the visible portion of the content can be passed in one html response and we can add remaining content in multiple requests. This will improve above-the-fold rendering time. More details here.
IssueList