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:
analytics.js
JavaScript by adding async attribute to its script
tag.google fonts
+ style.css
CSS by moving them to the bottom of the HTML.Index.html
now measures a score above 90 on PageSpeed Insights for both Mobile and Desktop devices.
Scope: Optimize
views/js/main.js
to makeviews/pizza.html
render with a consistent frame-rate at 60fps when scrolling.
Changes made on views/js/main.js
file:
document.getElementById()
and document.getElementsByClassName()
Web API calls throughout the code instead of document.querySelector()
and document.querySelectorAll()
, respectively; a faster way to access the DOM.document.body.scrollTop / 1250
outside the loop, as its value do not depend on the number of targeted elements.document.getElementById("randomPizzas")
and document.getElementById("movingPizzas1")
outside the loop so they will get to make only one DOM call.phase
and elem
variables outside the for
loops preventing them from being created every time the loop is executed.items.length
into a local variable for a more efficient iteration.backface-visibility: hidden
on the mover
class in views/css/style.css
file, 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.html
page, 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
:
changePizzaSizes
function, reducing repetition of code and by switching offsetWidth
calculation from px
to %
; also,document.getElementById()
and document.getElementsByClassName()
Web API calls for a faster access of the DOM.randomPizzas.length
into a local variable for a more efficient iteration.Scope: Download, configure and implement task runner on the project using Grunt.
How to run Grunt on this project?
src
folder, Gruntfile.js
and package.json
files are under one folder.npm update -g npm
.npm install -g grunt-cli
.Gruntfile.js
and package.json
are already configured for the project with the needed tasks and Grunt plugins –> you are ready to run Grunt:
npm install
.grunt
.