your local machine must node.js installed to allow the npm package manager to run:
to check if you already have it installed open a terminal and type:
npm -v
if this returns a version number (like '2.14.1'), you're fine.
If you get an error instead, you will have to install Node.js on to the local machine;
open a terminal where you want to clone to on your local machine then type:
git clone "https://github.com/klong/frontend-nanodegree-mobile-portfolio.git"
navigate into the 'frontend-nanodegree-mobile-portfolio' directory
cd frontend-nanodegree-mobile-portfolio
the easiest way to add the npm packages is to type in the terminal:
npm install
if you are on linux this should complete sucessfully, adding the npm packages to a new folder called node_modules
(I developed this on a Fedora 23 laptop)
If you are on mac OSX, I had problems with using the default npm install
installation method
This is because of a npm package called 'gulp-responsive' that uses a code library called sharp to create optimized images.
So, the best way to install on OS X is to install the library dependencies for sharp before running npm install
brew install homebrew/science/vips --with-webp --with-graphicsmagick
and when this long process ends;
npm install sharp
Then run the general npm install
command to add the npm packages needed ;
npm install
Sorry, I haven't tested this build process on a windows pc. (Please let me know if it works, so I can update this README file)
you will see a new direcory in the repo called node_modules
type:
gulp
you should see something like this:
note: the default gulp task is serving the web pages from the optimised build directory 'dist' (not from the 'src' directory').
Also, the terminal is 'watching' so you can't type any more commands into it while the task is running.
using a google chrome browser go to the local web address to see the page:
- Open a browser and visit localhost:8080
- Download and install ngrok to make your local server accessible remotely.
in a new terminal type:
ngrok http 8080
use google chrome to view the forwarding address
note: when you run it it will be given a different web address.
You can use this for input at the ;
An example result from my ngrok address.
Mobile Speed: 97, User experience: 100 | Desktop speed: 98 |
---|---|
- created an 'offline' gulp task
imagesForSite
to create resized and optimized images in anasset
directory within thesrc
directory. This directory is copied over to thedist
directory using the gulp task -build
. - minified & inlined externaly linked but critical fonts, CSS and javascript files. (see the
build-html
gulp task ingulpfile.js
) - used script
asyn
attribute for linked javascript filesanalytics.js
andperfmatters.js
. - minified
index.html
(removed comments & whitespace) - capitalizing the random-pizza names by using a
"pizzaName"
class CSS rule instead of javascript inmain.js
.
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.
- used 'offline' gulp task
imagesForSite
to build resized and optimized image assets (compressed.jpg
and.png
images with alpha). - minified
pizza.html
(removed comments & whitespace), CSS and javascript files using gulp taskbuild
.
most of the optimizations needed to improve the frame per seconds of the pizza.html
page are within the javascript of main.js
. See comments in src/views/js/main.js
for more examples.
- optimized expensive javascript operations and DOM selection calls inside for-loops within functions, to help increase the speed of both the initial
randomPizzas
andmover
elements being added to the DOM and the (low frames per second performance) 'janky' resizing and animation. - reduced the number of 'mover' class objects created from 200 to a smaller amount (approx 30-50) based on the browser window size.
- used style
transformX()
to animate themover
class objects as it is a composite-only operation and is GPU accelerated on some browsers. Added a CSSwill-change: transform
rule to themover
class for further look-ahead type browser optimisations ;
- used
npm
package manager andGulp
task runner to help automate some of the development tasks, such as, the building of optimized assets and adist
site, using usingngrok
andgulp
tasks for pagespeed insight rating, usingbrowser-sync
andwatch
to create a more dynamic feedback within the browser, help validate the html and CSS before submitting the project