Foundation Performance Optimization
Performance Tip: A well-optimized Foundation build can be under 20KB!
Custom Build Setup
Minimal Foundation Import
// app.scss - Only import what you need // Foundation settings @import 'settings'; // Core foundation @import 'foundation'; // Import only required components @include foundation-global-styles; @include foundation-grid; @include foundation-typography; @include foundation-button; @include foundation-forms; @include foundation-visibility-classes; @include foundation-float-classes; // Skip unused components // @include foundation-accordion; // @include foundation-accordion-menu; // @include foundation-badge; // ...
Build Size Comparison
| Build Type | CSS Size | JS Size | Total | Use Case |
|---|---|---|---|---|
| Full Build | 125KB | 84KB | 209KB | Development |
| CDN Version | 25KB (gzipped) | 12KB (gzipped) | 37KB | Production |
| Custom Minimal | 8KB (gzipped) | 4KB (gzipped) | 12KB | Optimized Apps |
Advanced Optimization Techniques
CSS Optimization
- Use PurgeCSS to remove unused CSS
- Enable CSS compression
- Use critical CSS inlining
- Implement CSS splitting
- Leverage browser caching
JavaScript Optimization
- Load Foundation JS async
- Use module federation
- Implement code splitting
- Tree-shake unused modules
- Lazy load components
Real-world Performance Tips
Webpack Configuration for Foundation
// webpack.config.js
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[contenthash].js',
},
module: {
rules: [
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader'
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
}),
],
optimization: {
minimizer: [
new CssMinimizerPlugin(),
],
splitChunks: {
chunks: 'all',
},
},
};Performance Monitoring
| Metric | Target | Tool | Improvement Tip |
|---|---|---|---|
| First Contentful Paint | < 1.5s | Lighthouse | Inline critical CSS |
| Largest Contentful Paint | < 2.5s | PageSpeed Insights | Optimize images |
| Total Blocking Time | < 200ms | WebPageTest | Defer non-critical JS |
| Bundle Size | < 100KB | Bundle Analyzer | Tree-shake Foundation |
CDN vs Self-Hosted
CDN Advantages
- Faster delivery via CDN
- Browser caching benefits
- No build process needed
- Quick prototyping
- Automatic updates
Self-Hosted Advantages
- Complete control
- Custom builds
- No external dependencies
- Better privacy
- Offline development
Quick Performance Checklist
- ✅ Use custom Foundation build
- ✅ Enable Gzip compression
- ✅ Implement browser caching
- ✅ Optimize images
- ✅ Minify CSS and JS
- ✅ Use CDN for assets
- ✅ Lazy load components
- ✅ Monitor performance