Optimized website here: https://spiningup.github.io/udacity-frontend-web-optimization/
- Add async to loading analytics.js
<script async src="https://www.google-analytics.com/analytics.js"></script>
- Add media option to loading print.css
<link href="css/print.css" rel="stylesheet" media="print">
- Inline 'css/style.css' in 'index.html'
- Compress and resize 'pizzeria.jpg'; compress all other images
- Use webfont to load google fonts at the end of body
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.16/webfont.js"></script>
<script>
WebFont.load({
google: {
families: ['Open+Sans:400,700']
}
});
</script>
- 'document.body.scrollTop' does not change, so move it to outside the loop:
function updatePositions() {
...
var items = document.querySelectorAll('.mover');
var bodytop = document.body.scrollTop;
for (var i = 0; i < items.length; i++) {
var phase = Math.sin((bodytop/ 1250) + (i % 5));
items[i].style.left = items[i].basicLeft + 100 * phase + 'px';
}
- There is no need to put 200 pizzas in the background, calculate the number of pizzas needed according to screen size:
document.addEventListener('DOMContentLoaded', function() {
...
var n = (Math.ceil(screen.width / 173.33) * Math.ceil(screen.height / 256));
for (var i = 0; i < n; i++) {
- Remove function 'determineDx' in 'main.js' and simplify 'changePizzaSizes'
function changePizzaSizes(size) {
switch(size) {
case "1":
newWidth = 25;
break;
case "2":
newWidth = 33.33;
break;
case "3":
newWidth = 50;
break
default:
console.log("bug in sizeSwitcher");
}
var allpizza = document.querySelectorAll(".randomPizzaContainer");
for (var i = 0; i < allpizza.length; i++) {
allpizza[i].style.width = newWidth + '%';
}
}