DEV Community

Cover image for How to reduce unused JavaScript in your code?

How to reduce unused JavaScript in your code?

Syket Bhattachergee on June 20, 2024

Cutting down on JavaScript is super important when you're building modern websites. It's a big deal for making your pages work well and be more eff...
Collapse
 
tracygjg profile image
Tracy Gilmore

Hi Syket,

Great article and love the graphics. Can I suggest, you might want to update your code examples to use syntax highlighting.

Best regards.

Collapse
 
syketb profile image
Syket Bhattachergee

@tracygjg Thank you so much, I will use syntax highlighting, and I will keep it in mind.

Collapse
 
nil012 profile image
Caca Prout

Yes, it will be very useful

Collapse
 
ayushh profile image
Ayush Sharma

great yr

Collapse
 
syketb profile image
Syket Bhattachergee

Thanks @ayushh

Collapse
 
koza_brajamagenta profile image
Koza Brajamagenta

Yeah, async import worked for me briliantly. My nextjs project has 2MB of initial JS (which is a lot)

And now its down to 1MB.

There's still some room for improvement, I'm sure I think I'll someday clean it 100% and it will be really satisfying when i've done that

Collapse
 
syketb profile image
Syket Bhattachergee

@koza_brajamagenta Right, there is always some scope to improve code, I wish you good luck. Thanks.

Collapse
 
neurabot profile image
Neurabot • Edited

I find article great somehow for reducing electric consumptions. It may unleash decarbonisation which is an actual warning through worldwide scale.

Thread Thread
 
syketb profile image
Syket Bhattachergee

@heyeasley Thanks, good to see you liked it.

Collapse
 
syketb profile image
Syket Bhattachergee

Thanks, @matin_mollapur Good to see you liked it. I will try my best to share the knowledge that I have gained over the years of experience in the industry. That makes me motivated. Thanks for comment.

Collapse
 
pengeszikra profile image
Peter Vivo • Edited

after minify those are look:

const vN=(a,b)=>a*b;vN(3, 4);
Enter fullscreen mode Exit fullscreen mode

but really useless because don't pass the return value to no one.

Collapse
 
adamjamiu profile image
Adam Jamiu

Hello Syket.
Thanks for the information ℹī¸. A developer needs modern framework like React js and Nextjs to foster this techniques when building a modern web app.

Best regards

Collapse
 
syketb profile image
Syket Bhattachergee

@adamjamiu You are on spot, Thanks for sharing your feedback.

Collapse
 
ichchhit_devkota_0a6e11cc profile image
Ichchhit Devkota

Loved it, will definitely keep this in mind.

Collapse
 
ezilemdodana profile image
Ezile Mdodana

Nice, thank you very much for sharing!

Collapse
 
orashus profile image
Rash Edmund Jr

Thanks a lot, honestly learned so much. Especially that comments really do affect build size