Skip to content
Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Gallery MKIII - WebP Conversion & Lazy Loading Guide

πŸ“‹ Overview

This guide explains how to optimize your art gallery website with:

  • WebP image conversion for 30-50% smaller file sizes
  • Lazy loading for faster page load times
  • Progressive enhancement for better user experience

πŸš€ Quick Start

Step 1: Install Dependencies

# Install Node.js (if not already installed)
# Download from: https://nodejs.org/

# Install required packages
npm install

Step 2: Convert Images to WebP

# Run the conversion script
npm run convert

This will:

  • Create All-DrawingsWebP/ folder with compressed WebP thumbnails
  • Create All-DrawingsWebPFull/ folder with full-size WebP images
  • Show conversion progress and file size savings

Step 3: Test Your Site

# Start local server
npm run serve
# Visit: http://localhost:8080

🎯 What Was Added

1. WebP Conversion Script (convert-to-webp.js)

What it does:

  • Converts PNG images to WebP format
  • Maintains image quality while reducing file size
  • Creates organized folder structure

Benefits:

  • 30-50% smaller file sizes
  • Faster loading times
  • Better user experience

2. Lazy Loading Script (script/lazy-loading.js)

What it does:

  • Only loads images when they're about to be visible
  • Provides WebP support with PNG fallback
  • Shows loading animations

Benefits:

  • Initial page loads 60-80% faster
  • Saves bandwidth for users
  • Works on all browsers

3. Updated HTML Files

Changes made:

  • Added lazy loading script to drawings.html and index.html
  • Automatic WebP detection and fallback
  • Smooth loading animations

πŸ› οΈ How It Works

Lazy Loading Process

  1. Page Load: Only visible images load immediately
  2. Scroll Detection: Detects when user scrolls near unloaded images
  3. Smart Loading: Loads images 100px before they become visible
  4. Format Selection: Uses WebP if supported, PNG if not

WebP Detection

// Browser automatically chooses best format:
// βœ… Modern browsers β†’ WebP (smaller files)
// βœ… Older browsers β†’ PNG (compatibility)

πŸ“ New Folder Structure

galleryMKIII/
β”œβ”€β”€ All-Drawings/           # Original full-size PNGs
β”œβ”€β”€ All-DrawingsCompressed/ # Compressed PNGs
β”œβ”€β”€ All-DrawingsWebP/       # πŸ†• Compressed WebP thumbnails
β”œβ”€β”€ All-DrawingsWebPFull/   # πŸ†• Full-size WebP images
β”œβ”€β”€ script/
β”‚   β”œβ”€β”€ darkmode.js
β”‚   └── lazy-loading.js     # πŸ†• Lazy loading script
β”œβ”€β”€ convert-to-webp.js      # πŸ†• Conversion script
└── package.json            # πŸ†• Dependencies

🎨 Customization

Adjust Image Quality

Edit convert-to-webp.js:

const QUALITY = 80; // Change to 60-100
// 60 = Smaller files, lower quality
// 90 = Larger files, higher quality
// 80 = Good balance (recommended)

Modify Loading Distance

Edit script/lazy-loading.js:

const options = {
  rootMargin: '100px', // Change to load earlier/later
  // '50px'  = Load closer to viewport
  // '200px' = Load further from viewport
};

Customize Loading Animation

Edit the CSS in lazy-loading.js:

.lazy-loading {
  opacity: 0.6;        /* Change loading opacity */
  filter: blur(2px);   /* Change blur amount */
  transition: all 0.3s ease; /* Change animation speed */
}

πŸ”§ Troubleshooting

Images Not Converting?

  1. Check Node.js installation:

    node --version  # Should show v16+ 
    npm --version   # Should show v8+
  2. Install dependencies:

    npm install
  3. Check file permissions:

    ls -la All-DrawingsCompressed/

Lazy Loading Not Working?

  1. Check browser console (F12 β†’ Console)

  2. Verify script is loaded:

    console.log(window.lazyLoader); // Should show object
  3. Test WebP support:

    // In browser console:
    window.lazyLoader.supportsWebP; // Should show true/false

Performance Issues?

  1. Reduce image quality in conversion script
  2. Increase loading distance in lazy loader
  3. Check network tab in browser dev tools

πŸ“Š Performance Benefits

Before Optimization:

  • Page load: ~3-5 seconds
  • Initial download: ~5-10MB
  • All images load immediately

After Optimization:

  • Page load: ~0.5-1 second
  • Initial download: ~500KB-1MB
  • Images load as needed

Expected Improvements:

  • 70-80% faster initial page load
  • 50-80% less bandwidth usage
  • 30-50% smaller image files

🌟 Best Practices

For Developers:

  1. Always test locally before deploying
  2. Keep original PNG files as backup
  3. Monitor loading performance with browser dev tools
  4. Update both WebP and PNG when adding new images

For Adding New Images:

  1. Add PNG to All-DrawingsCompressed/
  2. Run npm run convert to create WebP versions
  3. Images will automatically use lazy loading

For Production:

  1. Test on multiple browsers (Chrome, Firefox, Safari, Edge)
  2. Test on mobile devices
  3. Use browser dev tools to verify performance
  4. Consider using a CDN for even better performance

πŸ†˜ Need Help?

Common Commands:

# Reinstall dependencies
npm install

# Convert images again
npm run convert

# Start development server
npm run serve

# Check Node.js version
node --version

Browser Testing:

  1. Open browser dev tools (F12)
  2. Go to Network tab
  3. Refresh page and watch loading
  4. Check Console tab for any errors

File Structure Check:

# List WebP files
ls All-DrawingsWebP/

# Check file sizes
du -h All-DrawingsCompressed/ All-DrawingsWebP/

πŸ“ Git Management & Deployment

Repository Strategy

This project uses a build-time optimization approach:

βœ… COMMIT to git:

  • *.html - Your gallery pages
  • *.css - Styling files
  • *.js - Your custom scripts
  • README.md - Documentation
  • package.json - Dependencies list
  • convert-to-webp.js - Conversion script
  • .gitignore - Git ignore rules
  • build.sh - Build script
  • Optimized WebP images in All-DrawingsWebP/ and All-DrawingsWebPFull/ ✨

❌ DON'T COMMIT:

  • node_modules/ - Dependencies (auto-installed)
  • All-DrawingsCompressed/ - Source PNGs (converted and deleted)
  • package-lock.json - Auto-generated lockfile
  • System files (.DS_Store, Thumbs.db, etc.)

Build & Deploy Workflow

For Development:

# 1. Install dependencies and convert images
./build.sh

# 2. Test locally  
npm run serve

For Production Deploy:

# 1. Build optimized version (auto-deletes original PNGs)
npm run build

# 2. Deploy the entire folder to your web host
# (only WebP images remain, saving ~50% storage space)

Manual Commands:

# Convert images only
npm run convert

# Clean up original PNGs after conversion  
npm run cleanup

# Start dev server
npm run serve

Git Commands Reference

# Check what will be committed
git status

# Add new files (images, code, etc.)
git add .

# Commit changes
git commit -m "Add new artwork and optimizations"

# Push to repository  
git push origin main

Pro tip: The .gitignore file automatically excludes unnecessary files, keeping your repository clean and fast to clone!


πŸŽ‰ Congratulations!

You've successfully optimized your gallery with:

  • βœ… Modern WebP image format
  • βœ… Smart lazy loading
  • βœ… Automatic browser compatibility
  • βœ… Smooth loading animations

Your visitors will now enjoy:

  • Faster loading times
  • Less data usage
  • Smoother browsing experience

Happy coding! πŸš€

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages