Udacity Front-End Web Developer Nanodegree - Project
The aim of this project is to optimize the critical rendering path and make the index.html page render as quickly as possible by applying the techniques picked up in the Critical Rendering Path course.
Also we had to optimize FPS in pizza.html.("Do this after taking Browser Rendering Optimization course("https://www.udacity.com/course/ud860")")
-
GitHub project repository udacity: https://github.com/udacity/frontend-nanodegree-mobile-portfolio
-
My GitHub Project Repository(code of "after" website): https://github.com/kishorchouhan/Website-Optimization-Udacity-Project
-
My Project("Part 1") Website Is Hosted Here: https://kishorchouhan.github.io/Website-Optimization-Udacity-Project/index.html
-
My Project("Part 2: Pizza site") Website Is Hosted Here: https://kishorchouhan.github.io/Website-Optimization-Udacity-Project/views/pizza.html
To run the website and take code on local machine:
- Download the GitHub zip file or clone the repository onto your local workstation:
- Open a browser window and navigate to the index.html file in your directory.
To first start this project, we had to setup the project.
- Check out the repository
- To inspect the site on your phone, you can run a local server
$> cd /path/to/your-project-folder
$> python -m SimpleHTTPServer 8080
- Open a browser and visit localhost:8080
- Download and install ngrok to the top-level of your project directory to make your local server accessible remotely.
$> cd /path/to/your-project-folder
$> ./ngrok http 8080
- Copy the public URL ngrok gives you and try running it through PageSpeed Insights! Optional: More on integrating ngrok, Grunt and PageSpeed.
The following optimizations were done.
- Inline
style.css
in the index.html file. - Use a
media=print
query on print.css so that it is only rendered when printing. - Move google analytics to the end of the
body
tag and made its script load async. - Reduce dimensions of
pizerria.jpg
topizzeriaSmall.jpg
because width of that image on page is only 100px.
In this, we had to modify views/js/main.js
. FPS Counter/HUD Display useful in Chrome developer tools has been described here: Chrome Dev Tools tips-and-tricks.
To first test this, start views/pizza.html
in the browser and open Chrome Dev Tools. Have a look at the Performance or Timeline tab.
####Optimizing the Scrolling
I made the following changes in order to optimize the scrolling:
- In main.js, there was a loop that created 200 small moving pizzas in the background, which was an overkill because not all were displayed. I was able to cut that down to 20. The number is now dynamic, based on screen height.
- The updatePositions function had calculations within a loop that were redundant and could be moved outside of the loop.
####Optimizing the Pizza Resizing
I made the following changes to optimize the pizza resizing:
- The changePizzaSizes function was using the same thing multiple times so created a new myRandomPizzas variable.
- The determineDx function has no use so removed this function and embedded the switch object inside changePizzaSizes function.
- End the redundancy of changing width from px to % in changePizzaSizes function.
- The changePizzaSizes had a very inefficient for loop. I moved some calculations out of the for loop.
Your challenge, if you wish to accept it (and we sure hope you will), is to optimize this online portfolio for speed! In particular, optimize the critical rendering path and make this page render as quickly as possible by applying the techniques you've picked up in the Critical Rendering Path course.
To get started, check out the repository and inspect the code.
Some useful tips to help you get started:
- Check out the repository
- To inspect the site on your phone, you can run a local server
$> cd /path/to/your-project-folder
$> python -m SimpleHTTPServer 8080
- Open a browser and visit localhost:8080
- Download and install ngrok to the top-level of your project directory to make your local server accessible remotely.
$> cd /path/to/your-project-folder
$> ./ngrok http 8080
- Copy the public URL ngrok gives you and try running it through PageSpeed Insights! Optional: More on integrating ngrok, Grunt and PageSpeed.
Profile, optimize, measure... and then lather, rinse, and repeat. Good luck!
To optimize views/pizza.html, you will need to modify views/js/main.js until your frames per second rate is 60 fps or higher. You will find instructive comments in main.js.
You might find the FPS Counter/HUD Display useful in Chrome developer tools described here: Chrome Dev Tools tips-and-tricks.
- Optimizing Performance
- Analyzing the Critical Rendering Path
- Optimizing the Critical Rendering Path
- Avoiding Rendering Blocking CSS
- Optimizing JavaScript
- Measuring with Navigation Timing. We didn't cover the Navigation Timing API in the first two lessons but it's an incredibly useful tool for automated page profiling. I highly recommend reading.
- The fewer the downloads, the better
- Reduce the size of text
- Optimize images
- HTTP caching
The portfolio was built on Twitter's Bootstrap framework. All custom styles are in dist/css/portfolio.css
in the portfolio repo.