Kritim Yantra
Jul 16, 2025
Imagine this: Your Laravel+Vue application takes 8 seconds to load. Users are bouncing. Google ranks you poorly. Your competitors' apps feel instantaneous. What went wrong?
After optimizing dozens of Laravel-Vue applications, I've discovered the 7 most impactful performance boosters that most developers miss. Implement these today and watch your app speed skyrocket!
Problem: Default Vite builds include unnecessary code
Solution: Smart code splitting + compression
// vite.config.js
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks: (id) => {
if (id.includes('node_modules')) {
if (id.includes('lodash')) {
return 'vendor-lodash';
}
return 'vendor';
}
if (id.includes('stores')) {
return 'stores';
}
}
}
},
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
}
});
Pro Tip: Add this to your deployment script:
vite build --mode production --emptyOutDir
Before: 500KB initial load
After: 80KB initial load
// router.js
const routes = [
{
path: '/dashboard',
component: () => import('@/views/Dashboard.vue'), // Lazy-loaded
meta: { preload: true } // Hint for prefetching
}
];
// In your main layout
onMounted(() => {
router.getRoutes().forEach(route => {
if (route.meta.preload) {
router.preloadRoute(route.path);
}
});
});
Install:
composer require spatie/laravel-responsecache
php artisan vendor:publish --provider="Spatie\ResponseCache\ResponseCacheServiceProvider"
Usage:
// app/Http/Controllers/UserController.php
public function index()
{
return responsecache()
->remember(now()->addHours(12), function () {
return User::with('profile')->get();
});
}
Vite Plugin Setup:
npm install vite-plugin-image-optimizer --save-dev
Configuration:
// vite.config.js
import { imageOptimizer } from 'vite-plugin-image-optimizer';
export default defineConfig({
plugins: [
imageOptimizer({
jpg: { quality: 80 },
png: { quality: 80 },
webp: { lossless: false },
avif: { lossless: false },
cache: true,
cacheLocation: './node_modules/.cache/image-optimizer'
}),
]
});
Pinia Optimization Strategy:
// stores/auth.js
export const useAuthStore = defineStore('auth', {
state: () => ({
_user: null,
_lastHydrated: 0
}),
getters: {
user: (state) => {
// Only rehydrate if data is older than 5 minutes
if (Date.now() - state._lastHydrated > 300000) {
this.hydrate();
}
return state._user;
}
},
actions: {
async hydrate() {
this._user = await fetchUser();
this._lastHydrated = Date.now();
}
}
});
Laravel Filesystem Config:
// config/filesystems.php
'disks' => [
'cdn' => [
'driver' => 's3',
'url' => env('CDN_URL'),
'visibility' => 'public',
'bucket' => env('CDN_BUCKET'),
],
],
Vite Asset Handling:
// vite.config.js
export default defineConfig({
base: process.env.NODE_ENV === 'production'
? 'https://yourcdn.example.com/assets/'
: '/',
});
Install:
npm install vite-plugin-critical --save-dev
Configuration:
// vite.config.js
import critical from 'vite-plugin-critical';
export default defineConfig({
plugins: [
critical({
criticalUrl: 'http://localhost:3000',
criticalBase: './dist',
criticalPages: [
{ uri: '/', template: 'index' },
],
criticalConfig: {
width: 1300,
height: 900,
},
}),
],
});
Enable OPcache in PHP
[opcache]
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
Database Indexing
// Add to your migrations
$table->index(['email', 'created_at']);
Queue Workers
sudo supervisorctl restart laravel-worker:*
Lighthouse Score Booster
// Add to your main layout
<link rel="preconnect" href="https://api.yourdomain.com">
<link rel="preload" as="script" href="/assets/vendor.js">
After implementing these optimizations for a client:
Which optimization will you implement first? Have you discovered any performance secrets I missed? Let's discuss in the comments!
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google