chungsam / frontend-nanodegree-mobile-portfolio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Udacity Website Optimization Portfolio Project

This is my solution to the Website Optimization Portfolio Project, which is part of Udacity's Front-End Nanodegree Program. This project focuses on website performance/optimization, honing in the critical rendering path to make sure the website renders as quickly as possible.

Instructions

Serving the website locally and using ngrok to tunnel a url to localhost

  1. Install all dependent npm packages:
$> cd project-directory 
$> npm install
  1. Install gulp if you don't have it yet:
$> npm install -g gulp
  1. Run gulp in your terminal to start the task runner and start up a local dev server:
$> gulp
  1. Copy an ngrok executable to the main project directory and use it to tunnel a url to localhost (detailed instructions are in the readme section of original Udacity repo below):
$> ./ngrok http 3000

There are three required outcomes for this project:

  1. Optimize the main website's index.html so it achieves a Google PageSpeedInsights score of 90 or more.
  2. Optimize views./js/main.js and views/pizza.html so that the site renders with a consistent 60fps when scrolling.
  3. Optimize views/js/main.js so that the time to resize pizzas using the change pizza size slider is less than 5ms.

My Optimizations

Part 1: Optimize PageSpeed Insights score for index.html

  • Deferred loading of Google Analytics script
  • Moved fetching of web font to use @font-face in styles.css
  • Added "media=print" attribute to fetch print.css only for printing
  • Uglified and minified JS and CSS files
  • Resized and optimized image files to use base64 encoding
  • Used inline script tag to defer load main css file

Part 2: Optimize views/js/main.js and views/pizza/html to get rid of jank

  • Used cached value for document.body.scrolltop in updatePositions() to avoid forced synchronous layout
  • Simplified calculation of widths for pizza size slider by using CSS classes instead of JavaScript.
    • Got rid of in-line styling of width and height in randomPizzaContainer divs
    • Removed complicated JS function to calculate width, instead revised document.QuerySelectorAll to add the correct pizza size classes based on pizza size slider value
  • Used cached query results for .randomPizzaContainers
  • Used screen.height to determine number of background sliding pizzas to create

README from original Udacity repo below.


Website Performance Optimization portfolio project

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.

Getting started

####Part 1: Optimize PageSpeed Insights score for index.html

Some useful tips to help you get started:

  1. Check out the repository
  2. To inspect the site on your phone, you can run a local server
$> cd /path/to/your-project-folder
$> python -m SimpleHTTPServer 8080
  1. Open a browser and visit localhost:8080
  2. 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
  1. 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!

####Part 2: Optimize Frames per Second in pizza.html

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.

Optimization Tips and Tricks

Customization with Bootstrap

The portfolio was built on Twitter's Bootstrap framework. All custom styles are in dist/css/portfolio.css in the portfolio repo.

About


Languages

Language:HTML 65.3%Language:JavaScript 33.8%Language:CSS 0.9%