Giter VIP home page Giter VIP logo

optimize-bootstrap-docs's Introduction

Performance matters

Project setup

This project serves an adapted version of the Bootstrap documentation website. It is based on the github pages branche of Bootstrap.

Differences from actual Bootstrap documentation:

  • Added custom webfont
  • Removed third party scripts
  • The src directory is served with Express.
  • Templating is done with Nunjucks

Getting started

  • Install dependencies: npm install
  • Serve: npm start
  • Expose localhost: npm run expose

Optimizations

In various feature branches I've optimized different bolts and pieces of the Bootstrap documentation website. Below I explain for each feature branch what the benefit of the optimization is, and how it helps the end user. Included are screenshot comparisons of load times for each feature, compared to the original.

The final comparison shows all optimizations combined. The comparison screenshot graphs below are not representative of a production environment and may not be reproducable.

They were made using WebPagetest through an ngrok tunnel to a very simple ExpressJS server running on a development machine.

feature/async-css-loading

Asynchronous CSS loading was implemented using Filament Group's loadCSS. It is meant to be used only for non-critical CSS, e.g. CSS you don't need for the first meaningful paint.

This feature on its own is not much of an improvement for the end user. It even increases the timespan during which FOUT occurs. Other features like generating critical path CSS make this really shine, by reducing the time the parsing and loading of a CSS script is render-blocking.

original vs. async CSS loading

Added code can be found in layout.html.

feature/async-font-loading

Asynchronous font loading is implemented using Bram Stein's FontFaceObserver.

Font Face Observer is a small @font-face loader and monitor (3.5KB minified and 1.3KB gzipped) compatible with any web font service. It will monitor when a web font is applied to the page and notify you. It does not limit you in any way in where, when, or how you load your web fonts. Unlike the Web Font Loader Font Face Observer uses scroll events to detect font loads efficiently and with minimum overhead.

โ€” Bram Stein

FontFaceObserver is used to set a class on the html element as soon as the required fonts are loaded. That way, a user sees the default sans-serif fallback font until the class is switched. This enables the user to see the content around 0.5 seconds earlier, a long time when you are frustrated by your shitty CSS framework.

original vs. async font loading

Added code can be found in layout.html.

feature/caching-headers

Caching headers were set to a Max-Age of 3155760000, which translates to a full year. This makes sure clients (users) only have to request static assets once a year, after the browser cache is cleared, or after the assets have changed. This increases page load speed for the user, making content available faster.

original vs. caching headers

Note: the screenshot graph shows a repeat view because that is the most relevant view for this feature branch.

Added code can be found in server.js.

feature/cdn-assets

Bootstrap's CSS & Javascript as well as jQuery are often requested assets. As such they have been propagated around the world by various CDN's. A CDN will route a request for an asset to the server closest to the client requesting it, reducing the time bytes spend traveling.

original vs. CDN assets

Added code can be found in layout.html.

feature/concatenate-css

The CSS used in the web site has been concatenated together and optimized and minified using clean-css. This results in a smaller in total filesize, single CSS bundle, decreasing the time a browser needs to request and receive the resource and parse it.

original vs. concatenated CSS

Added code can be found in layout.html as well as in gulpfile.js.

feature/concatenate-javascript

The Javascript used in the web site has been concatenated together and mangled using uglify. This results in a single, smaller JS bundle, the time a browser needs to request and receive the resource.

original vs. concatenated JS

Added code can be found in layout.html as well as in gulpfile.js.

feature/css-critical-path

Addy Osmani's critical has been used to generate critical-path CSS for each page in the web site. The right critical-path CSS is included by the server on request.

original vs. critical-path CSS

Added code can be found in critical-path.js as well as in layout.html and server.js.

feature/gzip

The compression package is used to compress files sent to the browser. This reduces page load time for the end user.

original vs. gzip

Added code can be found in server.js

feature/image-optimization

All images in the repository have been optimized using imagemin. This reduces filesize.

Additionally, all images have been converted to WebP, and img tags have been replaced with picture tags, with a source for the WebP image, and a fallback to the regular image for browsers that do not support WebP.

original vs. concatenated JS

Relevant added code can be found in gulpfile.js

release/2.0.0

All of the above optimizations combined yield the largest effect on the time to first meaningful paint, e.g. the time until a user has something useful on their screen.

original vs. concatenated JS

All of the changes above can be found merged in release/2.0.0.

All changes together net a 100/100 result on Google's Pagespeed Insights, for both desktop and mobile.

Optimization conclusion

All in all, the documentation website sports so much unused CSS and Javascript on each page, the best optimization would be to chuck it all and do a complete, lean rewrite of the required stylesheets and Javascript. That completely defeats the purpose of a Bootstrap documentation site, where among other things, it would be nice if Bootstrap is showcased.

optimize-bootstrap-docs's People

Contributors

nickrttn avatar joostf avatar decrek avatar

Watchers

James Cloos avatar  avatar

optimize-bootstrap-docs's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.