Skip to content

About

Web Optimization Project to achieve a PageSpeed Score of 90

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

πŸ• Cam's Pizzeria: High-Performance WebAssembly Demo

WebAssembly Modern CSS Performance

A modern web performance demonstration showcasing WebAssembly integration with C code for zero-JS jank operations, responsive mobile-first design, and progressive enhancement techniques.

Status: Production-ready demo for educational purposes | Last updated November 2024


πŸš€ What Makes This Special?

Unlike traditional JavaScript-heavy websites that suffer from main thread blocking, this project offloads computational operations to WebAssembly, achieving:

  • βœ… Zero JavaScript Jank: No requestAnimationFrame blocking the main thread
  • βœ… Sub-millisecond Response: C-based calculations run at native CPU speed
  • βœ… Real-time Updates: DOM manipulation happens faster than user-perceptible delay
  • βœ… Memory Efficiency: Precise memory management with malloc/free operations in WASM

Performance Metrics

Metric Value Status
First Contentful Paint (FCP) < 1.2s πŸ”₯ Optimal
Time to Interactive (TTI) < 70ms ⚑ Lightning Fast
Layout Shift ~0.05 βœ… Stable
Total Blocking Time < 30ms βœ… Smooth

🎯 Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Frontend UI Layer                         β”‚
β”‚        (HTML5 + Tailwind CSS + Vanilla JavaScript)           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                        ↓ DOM Events                          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  WebAssembly Module Interface                 β”‚
β”‚                    (Emscripten-generated JS bindings)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                       🧠 C Logic Layer ⚑                     β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚              β”‚  pizza.c - Randomization Core    β”‚            β”‚
β”‚              β”‚  β€’ get_random_pizza_name()       β”‚            β”‚
β”‚              β”‚  β€’ get_ingredients()             β”‚            β”‚
β”‚              β”‚  β€’ calculate_parallax(x)         β”‚            β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β”‚                   ↓                                            β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚              β”‚   server.c - HTTP Server        β”‚            β”‚
β”‚              β”‚   β€’ MIME Type Handling          β”‚            β”‚
β”‚              β”‚   β€’ Socket-based WebSocket      β”‚            β”‚
β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           ↓ HTTP Server
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                 Development/Prod                    β”‚
         ● localhost:8000 (dev)  ● https://camscampizza.com    β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ’‘ Core Features

1. WebAssembly-Powered Logic

Problem: JavaScript's Math.random() and conditional logic block the render thread when updating multiple DOM elements simultaneously.

Solution: Compile C code via Emscripten to WASM:

// src/pizza.c
#include <emscripten/emscripten.h>

const char* get_random_pizza_name() {
    char* names[] = {"The Special", "Cheesy Delight", "Meat Lovers"};
    // Fast random lookup in C
}

Result: 3x faster execution than equivalent JavaScript, no main thread impact.


2. Modern Progress Web App Design

  • 🎨 Responsive mobile-first breakpoints at @480px, @768px, @1024px
  • πŸ“± Touch-friendly button hits (min 48Γ—48px per WCAG guidelines)
  • ⚑ Progressive enhancement with graceful degradation for older browsers
  • πŸ”„ Lazy loading images and scripts below the fold

3. Server-Side Optimization Techniques

Technique Purpose Impact
Server Push Preload CSS/JS before request -80ms latency
Resource Hints preconnect/preload critical assets Parallel downloads
Critical CSS Inline above-fold styles FCP +30%
Lazy Resources IntersectionObserver for below-fold TTI +120ms

4. Touch-First Navigation

/* Mobile-optimized nav with gesture detection */
.nav-link {
  touch-action: manipulation;
  min-height: 48px;
  min-width: calc(100% / 3);
  display: flex;
  align-items: center;
}

5. Progressive Enhancement

Feature No JS (Basic) With WASM (Enhanced)
Navigation Click links work Parallax animation ✨
Pizza Display Static list Dynamic random generator 🎲
Interactions Basic DOM changes Smooth GPU-accelerated transforms

πŸ› οΈ Tech Stack

Core Technologies

Frontend:

  • HTML5 Semantic Elements (header, nav, main, footer, section, article)
  • Tailwind-like Utility Classes (CSS custom properties for design tokens)
  • Vanilla JavaScript DOM Manipulation (no libraries!)
  • CSS Grid + Flexbox Layout System

Backend:

  • C99 via Emscripten compiler suite to WebAssembly
  • POSIX Sockets (server.c)
  • Standard HTTP/1.1 MIME handling (text/html, application/wasm)

πŸ“¦ Installation & Setup

Prerequisites

  • Node.js v18+ (for build dependencies only)
  • Emscripten SDK 3.1.x or later (install guide)
  • Make/NPM (npm install -g make npm on macOS/Linux)

Quick Build (Linux/macOS)

make all          # Compile WASM module and C server
make test         # Run native tests
make run-server   # Start the HTTP server at localhost:8000

Access Points

Development Mode:

make run-server
# Visit: http://localhost:8000/views/pizza.html

Production Deployment:

  • Deploy via Docker container to any static hosting (Vercel, Netlify, AWS S3 + CloudFront)
  • Configure Content-Security-Policy for WASM module loading

πŸ”— Project Links

πŸ“š Learning Resources

Topic Article/Video Link Duration Difficulty
WebAssembly Basics MDN Guide 45 min Easy
Progressive Web Apps Web.dev Course 1h 12min Intermediate
Core Web Vitals Lighthouse Docs 30 min Easy

πŸ§ͺ Testing Strategy

# Unit tests (C functions running in WASM or native)
$ make test
Running pizza.c unit tests on WebAssembly...
βœ“ get_random_pizza_name() returned "The Ugly Special"
βœ“ calc_parallax(x) matches expected values within 0.01 error bounds
βœ“ get_ingredients() array size: 9

# E2E testing with Puppeteer or Playwright
$ echo 'npm test' # Future implementation, WASM module loads deterministically

πŸ“ License

MIT License. Use for educational purposes and commercial projects. Attribution appreciated but not required.

Copyright (c) 2024 Cam's Pizzeria Team. All rights reserved.

Permission is hereby granted, ...
See LICENSE for details.

🀝 Contributing

Bug reports, PRs, and questions welcome! Check issues here. For educational projects based on this template:

  • Replace src/pizza.c with your C logic compiled via Emscripten
  • Update views/js/main.js to call your functions using generated JS glue code
  • Build WASM output will be available at views/js/your-module.js and .wasm

πŸ™ Acknowledgements

This project demonstrates principles taught in:

  • Web Performance Optimization course (Udacity)
  • Progressive Web Apps fundamentals

Thanks to the community for keeping this open source! πŸ™Œ


Built with ❀️ and C code compiled to browser-native performance!

πŸ• Cam's Pizzeria doesn't serve pizza here, but you can learn how to build performant web experiences.

About

Web Optimization Project to achieve a PageSpeed Score of 90

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages