Project @Udacity #frontendnanodegree
Scope: Optimize PageSpeed Insights score of at least 90 for Mobile and Desktop for
index.html.
Defined the CRP Metrics and optimized them by:
- reducing the number of critical resources
- removed render-blocking
analytics.jsJavaScript by adding async attribute to itsscripttag. - removed render-blocking
google fonts+style.cssCSS by moving them to the bottom of the HTML.
- removed render-blocking
- reducing the number of critical bytes of critical resources
- used Grunt build tool to perform optimization such as minification of CSS and JS and image optimization (see Step4 for details).
- hence, shortening the critical path length
Index.html now measures a score above 90 on PageSpeed Insights for both Mobile and Desktop devices.
Scope: Optimize
views/js/main.jsto makeviews/pizza.htmlrender with a consistent frame-rate at 60fps when scrolling.
Changes made on views/js/main.js file:
- Calculated dinamically the number of pizzas needed to fill the screen, based on browser window resolution.
- Used
document.getElementById()anddocument.getElementsByClassName()Web API calls throughout the code instead ofdocument.querySelector()anddocument.querySelectorAll(), respectively; a faster way to access the DOM. - Fixed the major forced synchronous layout (FSL) issue by defining
document.body.scrollTop / 1250outside the loop, as its value do not depend on the number of targeted elements. - Also, moved
document.getElementById("randomPizzas")anddocument.getElementById("movingPizzas1")outside the loop so they will get to make only one DOM call. - Declared the
phaseandelemvariables outside theforloops preventing them from being created every time the loop is executed. - Stored
items.lengthinto a local variable for a more efficient iteration. - Added
backface-visibility: hiddenon themoverclass inviews/css/style.cssfile, so the backside of the rotated elements are not going to be painted when scrolling the page.
Now, views/pizza.html renders with a consistent frame-rate at 60fps when scrolling.
Scope: Using the pizza size slider on the
views/pizza.htmlpage, resize pizzas in less than 5ms.
After tracing and idetifying the performance issue in DevTools/Timeline, I found that an FSL was causing the high resize time of the pizzas.
Changes made on resizePizzas function in views/js/main.js:
- Fixed FSL by refactoring
changePizzaSizesfunction, reducing repetition of code and by switchingoffsetWidthcalculation frompxto%; also, - Switched to
document.getElementById()anddocument.getElementsByClassName()Web API calls for a faster access of the DOM. - Stored
randomPizzas.lengthinto a local variable for a more efficient iteration. - Time to resize pizzas now is less then 1ms.
Scope: Download, configure and implement task runner on the project using Grunt.
How to run Grunt on this project?
- Download the project assets and make sure
srcfolder,Gruntfile.jsandpackage.jsonfiles are under one folder. - Open your terminal window.
- Ensure that you have the npm package manager or Node.js installed and up-to-date by running
npm update -g npm. - Install Grunt's command line interface (CLI) by running
npm install -g grunt-cli. - Since,
Gruntfile.jsandpackage.jsonare already configured for the project with the needed tasks and Grunt plugins --> you are ready to run Grunt:- Go to the project's root directory in your terminal.
- Install project dependencies by running
npm install. - Run Grunt with
grunt.