Giter Club home page Giter Club logo

udacity-fend-mobile-portfolio-optimization's Introduction

Website Performance Optimization portfolio project

It is a challenge I have accepted 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 I've picked up in the Critical Rendering Path course.

To get started, check out the repository, 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 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.
  2. Then Profile, optimize, measure... and then lather, rinse, and repeat.

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.

Optimize the Critical Rendering Path

1. Make non-block rendering for CSS and Javascripts before tag in the "index.html".

  • Adding async to javascript tag which makes it says, "I don't want the browser to stop what it's doing while it's downloading this script." It works the same to put the javascript link at the bottom of the page like below.

  • tage makes the css to load asynchronously.

  • The critical path CSS is created by using this online tool: https://jonassebastianohlsson.com/criticalpathcssgenerator/

    		<!-- asynchronously load the crtical css -->
         <link href="css/style.min.css" rel="stylesheet">
         <link href="css/print.min.css" rel="stylesheet" media="print">
         <!-- make non-block rendering Javascripts -->
         <script>
             (function(w, g) {
                 w['GoogleAnalyticsObject'] = g;
                 w[g] = w[g] || function() {
                     (w[g].q = w[g].q || []).push(arguments)
                 };
                 w[g].l = 1 * new Date();
             })(window, 'ga');
         </script>
         <script async src="js/perfmatters.js"></script>
      </body>

2. Resize and compress the images for fast loading.

I used the free image optimizer tools online: http://jpeg-optimizer.com/

There are also other great tools to use online:

3. Minimize the CSS for fast loading.

Using online CSS minimizing tool: https://cssminifier.com/

Optimize the Frame Rate

By reviewing the Timeline in WebTools, the bottleneck of the FPS is when calling the update Position. Here is my revise to the updatePosition() function below:

    var items = document.getElementsByClassName('mover');
    var tops = document.body.scrollTop / 1250;
	//make a for loop for phase to give a exact number that phase and document.body.scrollTop give per iteration
    var phases = [];
    for (var i = 0; i < 5; i++) {
	    phases.push(Math.sin(tops + i));
    }
    var phase;
    for (var i = 0; i < items.length; i++) {
	    phase = phases[i%5];
        items[i].style.left = items[i].basicLeft + 100 * phase + 'px';
    }

Optimize the Computation Efficiency

1. Faster Web API calls

document.getElementById() or document.getElementByClassName()

instead of

document.querySelector() or document.querySelectorAll()

2. Provide fixed value for newwidth and dx.

At line 473 and 474, since the pizza sizes are all the same, you can provide a fixed value prior starting the iteration/loop for both variables. Perhaps the first selector ([0]) from the randomPizzaContainer variable.

var dx = determineDx(container[0], size);
var newwidth = (container[0].offsetWidth + dx) + 'px';
for (var i = 0; i < containerLength; i++) {
  container[i].style.width = newwidth;
}

Same reason for document.getElementsByClassName('randomPizzaContainer') at line 467.

//create a local variable to save document.getElementsByClassName('randomPizzaContainer') 
var container = document.getElementsByClassName('randomPizzaContainer');

//save the array length in local variable, so the array'e length property is not accessed to check its value at each iteration. It is more efficiency.
var containerLength = container.length;

Same reason for pizzasDiv at line 494.

var pizzasDiv = document.getElementById('randomPizzas');

Same reason for elem at line 598, and same reason for movingPizzas at line 600

3. Dynamically calculations

I could only handful a pizza that show up on the screen at any given scroll, that amount doesn't look dynamically calculate the number of pizza needed to fill the screen.

var pizzaRows = window.innerHeight / 100;
var pizzaCols = window.innerWidth / 73.333;

//Declaring the elem variable outside the loop will prevent it from being created every time the loop is executed.
var elem;
//document.getElementById() Web API call is faster.
var movingPizzas = document.getElementById("movingPizzas1");
for (var i = 0; i < (pizzaRows * pizzaCols); i++) {
elem = document.createElement('img');
...

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.

Sample Portfolios

Feeling uninspired by the portfolio? Here's a list of cool portfolios I found after a few minutes of Googling.

udacity-fend-mobile-portfolio-optimization's People

Contributors

durant-udacity avatar safadurimo avatar walesmd avatar susansmith avatar cameronwp avatar mrk-nguyen avatar nicolasartman avatar aaronbutler avatar

Watchers

James Cloos avatar James Wang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.