dev-resources.site
for different kinds of informations.
Lighter LoDash Builds for Laravel
Published at
1/5/2021
Categories
laravel
lodash
performance
Author
Mike Healy
Laravel projects often include the LoDash JavaScript utility library. It contains handy utilities, however if you don't need its entire suite you may be serving unnecessary JS to your users that you never run.
LoDash supports custom builds to avoid this problem, and it's fairly easy to modify your Laravel's bootstrap.js file trim down the features you're loading.
Default resources/js/bootstrap.js
window._ = require('lodash'); // 71.1K (gzipped: 24.6K)
Customizing the build
In my case I was only using the throttle and debounce helpers from LoDash. This can be mapped to the window lodash object (typically _) like so:
window._ = require('lodash/core') // 14K (gzipped: 5.3K)
window._.debounce = require('lodash/debounce') // 3.5K (gzipped: 1.4K)
window._.throttle = require('lodash/throttle') // 3.7K (gzipped: 1.4K)
My application JS can then call _.debounce()
and _.throttle()
for those functions with a significant saving to my JS bundle size.
Articles
8 articles in total
Using S3 Lifecyle Rules with Spatie Laravel Backups
read article
Running Jest with a Vue2 application
read article
Dark Mode Toggle with Alpine & Tailwind
read article
Lighter LoDash Builds for Laravel
currently reading
16GB or 32GB RAM for Web Development?
read article
Help: Should a new service worker force a refresh to update a PWA?
read article
How to Build an Image Carousel
read article
Improving Performance for Low-Bandwidth Users with save-data
read article
Featured ones: