ah teaches web design and development: 11 Turning it to 11

ah teaches web design and development: 11 Turning it to 11 — A slide deck

Turning it to 11

Lecture outline

Covered this week:

  • Speed optimization of website
  • Final course considerations

Lecture slides will be made available on the day of the lecture.

But These All Go to Eleven

Page Speed Optimization

To get our pages to render as efficiently as possible, we need to keep in mind a couple of things:

  • Render blocking
  • Compression
  • Caching
  • Critical rendering path

Render Blocking

Anything that appears in the head of our HTML must be loaded before the page can start to render.

<meta charset="utf-8">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/grids.css">
<link rel="stylesheet" href="css/animations.css">
<link rel="stylesheet" href="css/jquery.ui.css">
<link rel="stylesheet" href="css/lightbox.css">

Preprocessing, Compression & Request Reduction

"Minifying" your files

Using tools such as preprocessing we can remove all the extra spaces and comments in our files and deploy them online. We can also use such tools to to reduce requests.

/* We can set up preprocessing to combine files */

@import "main.scss";
@import "grids.scss";
@import "animations.scss";

Transfer Compression

We can compress images and all the extra spaces out of our text files, but we can also compress our files for transfer as well. Using a server-side file (on Apache servers) called .htaccess, we can set some specifications as to how our page should use compression.

# An .htaccess file allows us to control server-side redirection and delivery

<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript


To enable caching of files, we can again use our .htaccess file to tell the user's browser to cache content accordingly.

# Enabling caching in .htaccess

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType text/css "access 1 week"
ExpiresDefault "access 1 day"

Critical Render Path

If we are getting into extensive page-speed optimization, we begin considering what is absolutely necessary for the user to get first (when they access the page), as opposed to what can wait until later.

<!-- Here we put in the 'critical' CSS for the page -->

<script src="js/loadCSS.js">
// Here we load non-critical CSS



// We need to collect ourselves all the elements we have flagged for 'lazy loading':
var lazyloads = document.getElementsByClassName("lazyload");

// Then select one based on a action (i.e. a click, or a scroll):
otherElement.addEventListener("click", function() {
var element = lazyloads[0];});

// Then swap out attributes:
var img = element.getAttribute("data-src");
element.setAttribute("src", img);


<img src="blank.png" data-src="actual-image.jpg" class="lazyload" alt="...">
<noscript><img src="actual-image.jpg" alt="..."></noscript>

P3 Code Rubric

"B: Code uses preprocessing and compression to increase page-loading efficiency..."

You can achieve this simply through minifying your CSS using Prepros or other online tools.

P3 Code Rubric

"A: Code uses preprocessing, compression, and request reduction to increase page-loading efficiency..."

You can achieve this through reducing the number of files being loaded when the page first opens up: i.e. only loading one CSS file (instead of multiple files) and, or, lazyloading your images.

Bonus Office Hours

I am offering some final bonus office hours for those who would like some additional project assistance. Please note that these office hours are by email appointment only:

  • Monday, November 19th; 8:30-9:30am
  • Thursday, November 22nd; 12:30-1:30pm (on Burnaby)
  • Monday, November 26th; 8:30-9:30am
  • Tuesday, November 27th; 11-12pm

Next Week

In lecture next week we will be doing your final reading quiz and debugging. Please make sure to bring your portfolio websites as complete as possible and ready-to-go for lecture next week.

Change in Office Hours

Please note that Friday, November 23rd's office hours are cancelled. Should you need to meet to make-up for that availability, please send me an email to arrange a time that works for you.