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
# Install Node.js (if not already installed)
# Download from: https://nodejs.org/
# Install required packages
npm install# Run the conversion script
npm run convertThis 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
# Start local server
npm run serve
# Visit: http://localhost:8080What 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
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
Changes made:
- Added lazy loading script to
drawings.htmlandindex.html - Automatic WebP detection and fallback
- Smooth loading animations
- Page Load: Only visible images load immediately
- Scroll Detection: Detects when user scrolls near unloaded images
- Smart Loading: Loads images 100px before they become visible
- Format Selection: Uses WebP if supported, PNG if not
// Browser automatically chooses best format:
// β
Modern browsers β WebP (smaller files)
// β
Older browsers β PNG (compatibility)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
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)Edit script/lazy-loading.js:
const options = {
rootMargin: '100px', // Change to load earlier/later
// '50px' = Load closer to viewport
// '200px' = Load further from viewport
};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 */
}-
Check Node.js installation:
node --version # Should show v16+ npm --version # Should show v8+
-
Install dependencies:
npm install
-
Check file permissions:
ls -la All-DrawingsCompressed/
-
Check browser console (F12 β Console)
-
Verify script is loaded:
console.log(window.lazyLoader); // Should show object
-
Test WebP support:
// In browser console: window.lazyLoader.supportsWebP; // Should show true/false
- Reduce image quality in conversion script
- Increase loading distance in lazy loader
- Check network tab in browser dev tools
- Page load: ~3-5 seconds
- Initial download: ~5-10MB
- All images load immediately
- Page load: ~0.5-1 second
- Initial download: ~500KB-1MB
- Images load as needed
- 70-80% faster initial page load
- 50-80% less bandwidth usage
- 30-50% smaller image files
- Always test locally before deploying
- Keep original PNG files as backup
- Monitor loading performance with browser dev tools
- Update both WebP and PNG when adding new images
- Add PNG to
All-DrawingsCompressed/ - Run
npm run convertto create WebP versions - Images will automatically use lazy loading
- Test on multiple browsers (Chrome, Firefox, Safari, Edge)
- Test on mobile devices
- Use browser dev tools to verify performance
- Consider using a CDN for even better performance
# Reinstall dependencies
npm install
# Convert images again
npm run convert
# Start development server
npm run serve
# Check Node.js version
node --version- Open browser dev tools (F12)
- Go to Network tab
- Refresh page and watch loading
- Check Console tab for any errors
# List WebP files
ls All-DrawingsWebP/
# Check file sizes
du -h All-DrawingsCompressed/ All-DrawingsWebP/This project uses a build-time optimization approach:
β COMMIT to git:
*.html- Your gallery pages*.css- Styling files*.js- Your custom scriptsREADME.md- Documentationpackage.json- Dependencies listconvert-to-webp.js- Conversion script.gitignore- Git ignore rulesbuild.sh- Build script- Optimized WebP images in
All-DrawingsWebP/andAll-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.)
# 1. Install dependencies and convert images
./build.sh
# 2. Test locally
npm run serve# 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)# Convert images only
npm run convert
# Clean up original PNGs after conversion
npm run cleanup
# Start dev server
npm run serve# 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 mainPro tip: The .gitignore file automatically excludes unnecessary files, keeping your repository clean and fast to clone!
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! π