Performance Optimization
FreshJuice DEV is built with performance in mind, featuring Flying Pages for instant navigation, optimized asset loading, and modern JavaScript practices.Flying Pages Integration
FreshJuice DEV includes Flying Pages for intelligent link prefetching, making navigation feel instant.How It Works
Flying Pages is automatically initialized insource/js/main.js:53:
What Gets Prefetched
By default, Flying Pages intelligently prefetches:- Links visible in the viewport
- Links on hover (with delay)
- Links on touchstart (mobile)
Configuration Options
Customize Flying Pages behavior insource/js/main.js:
Common Configurations
Aggressive prefetching:Benefits
- Near-instant navigation: Pages load almost instantly
- Improved Core Web Vitals: Better FCP and LCP scores
- No breaking changes: Works with existing links
- Smart prefetching: Only prefetches what’s needed
Image Optimization
Lazy Loading
FreshJuice DEV implements lazy loading for optimal performance.In Sections
Setloading attribute in section modules (theme/sections/multi-column-content.html:21):
Loading Strategies
Hero images (above-the-fold):Responsive Images
Use HubSpot’s sizing options for responsive images:auto: Automatic sizingauto_custom_max: Max width/height with aspect ratioexact: Fixed width/height
Image Best Practices
- Use appropriate formats: WebP when possible
- Optimize before upload: Compress images before uploading to HubSpot
- Use CDN URLs: HubSpot automatically serves from CDN
- Set dimensions: Always specify width and height to prevent layout shift
JavaScript Optimization
Module Bundling
FreshJuice DEV uses esbuild for fast bundling (package.json:14):
Tree Shaking
Only import what you need:Conditional Loading
Load scripts only when needed (source/js/main.js:36):
Alpine.js Optimization
Use x-intersect for Lazy Initialization
Use x-collapse for Smooth Transitions
Defer Non-Critical Alpine Components
CSS Optimization
Tailwind CSS Purging
Tailwind automatically removes unused CSS in production builds. Build command (package.json:12):
Critical CSS
For better FCP, inline critical CSS in your base template:CSS Best Practices
- Use Tailwind utilities: Avoid custom CSS when possible
- Minimize custom CSS: Keep
module.cssfiles minimal - Use Alpine directives: Replace CSS animations with Alpine when interactive
Build Optimization
Development Workflow
Watch mode for rapid development (package.json:19):
watch:tailwind: Auto-rebuild CSS on changeswatch:js: Auto-bundle JS on changeswatch:hubspot: Auto-upload to HubSpot on changes
Production Build
Optimized production build (package.json:20):
- Clean temp and dist folders
- Bundle and minify JavaScript
- Build and purge Tailwind CSS
- Create deployment ZIP
Performance Monitoring
Core Web Vitals
Monitor these key metrics:- LCP (Largest Contentful Paint): < 2.5s
- FID (First Input Delay): < 100ms
- CLS (Cumulative Layout Shift): < 0.1
Tools
- Google PageSpeed Insights: Overall performance score
- Chrome DevTools: Network and performance profiling
- Lighthouse: Automated auditing
- WebPageTest: Detailed waterfall analysis
Advanced Optimization Techniques
Preconnect to External Domains
Add to your base template:Resource Hints
Preload critical assets:Font Optimization
Use font-display for web fonts:Service Worker (Advanced)
For offline support and caching, consider implementing a service worker:Performance Checklist
Images
- Lazy load below-the-fold images
- Disable lazy loading for hero images
- Use responsive sizing (auto_custom_max)
- Compress images before upload
- Specify width and height attributes
JavaScript
- Bundle with esbuild
- Tree-shake unused code
- Load scripts asynchronously when possible
- Use Alpine.js directives efficiently
- Initialize Flying Pages
CSS
- Build Tailwind with purge enabled
- Minimize custom CSS
- Inline critical CSS
- Remove unused styles
General
- Enable HubSpot CDN
- Minimize HTTP requests
- Use browser caching
- Monitor Core Web Vitals
- Test on real devices
Debugging Performance Issues
Chrome DevTools Performance Tab
- Open DevTools (F12)
- Go to Performance tab
- Click Record
- Interact with your page
- Stop recording
- Analyze the timeline
Network Waterfall
- Open DevTools Network tab
- Reload page
- Look for:
- Large resources
- Render-blocking resources
- Long request chains
- Slow server responses
Console Warnings
Watch for performance warnings:Performance Budget
Set performance budgets for your project:- Total page size: < 2MB
- JavaScript bundle: < 200KB (gzipped)
- CSS bundle: < 50KB (gzipped)
- Largest image: < 300KB
- Time to Interactive: < 3s
Next Steps
- Explore Alpine.js documentation
- Learn about Custom Sections
- Review Tailwind CSS optimization
- Check Flying Pages documentation
Resources
- Flying Pages: GitHub Repository
- Web.dev: Performance Best Practices
- HubSpot: CMS Performance Guide