How to make your JavaScript Bundle Smaller

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ธ.ค. 2024

ความคิดเห็น • 148

  • @theweebtoblame5402
    @theweebtoblame5402 2 ปีที่แล้ว +42

    Wow! I never knew about this, now my sites can be visited by people who aren't on localhost!

  • @hashtagPoundsign
    @hashtagPoundsign 2 ปีที่แล้ว +63

    The classic "wait for them to log in, then hit them with megabytes" strategy. Jokes aside, thank you for this!!!

  • @anweshandev
    @anweshandev 2 ปีที่แล้ว +23

    I cannot emphasize how important & rightly timed this video is for me. I am literally working on a project, and embarrassing it may sound the chunks are oversized. Saw this video and my bundle sizes are literally the smallest in the team.
    Your hard work is commendable! Thanks Jeff... Looking forward more to you reading my mind 😄

  • @damin1916
    @damin1916 2 ปีที่แล้ว +3

    my new favourite channel, sometimes when im coding i just remember something from a vid 2 weeks ago and it saves me

  • @vikingthedude
    @vikingthedude 2 ปีที่แล้ว +140

    Im loving vite and the other new js frameworks like astro etc. It’s painful to have to face so many new frameworks in the js ecosystem. But it seems we’re moving in the right direction. Hopefully we’ll be a bit more settled in the future.

    • @alexnezhynsky9707
      @alexnezhynsky9707 2 ปีที่แล้ว +21

      Famous last words (as history shows)

    • @MrEnsiferum77
      @MrEnsiferum77 2 ปีที่แล้ว +8

      If looking at all this framework is the right direction, than that's why web is so doomed. Solving same existing problems for years but in different framework.

    • @muhammadmejanulhaque3305
      @muhammadmejanulhaque3305 2 ปีที่แล้ว +1

      I think Astro will succeed in that. you get to write vanilla js or other frameworks. it also use vite

    • @adekorir
      @adekorir 2 ปีที่แล้ว

      I'm loving both Astro and Vite.

    • @vikingthedude
      @vikingthedude 2 ปีที่แล้ว +1

      @@MrEnsiferum77 We need frameworks because the native web APIs suck ass. So until they don't we're using frameworks

  • @TheusKhan
    @TheusKhan 2 ปีที่แล้ว +7

    I'm loving this channel and the humor.
    Great videos as always!

  • @AByteofCode
    @AByteofCode 2 ปีที่แล้ว +12

    Great video my man! Good luck with this new channel and keep up the good work :)

    • @qexat
      @qexat 2 ปีที่แล้ว +1

      oh hi you lol

    • @AByteofCode
      @AByteofCode 2 ปีที่แล้ว +1

      @@qexat Lol hi

    • @dakata2416
      @dakata2416 2 ปีที่แล้ว +3

      a monad is a

    • @AByteofCode
      @AByteofCode 2 ปีที่แล้ว +1

      @@dakata2416 sorm form of monoid :)

    • @dakata2416
      @dakata2416 2 ปีที่แล้ว

      @@AByteofCode in the category of no bitches

  • @matteoalberghini2040
    @matteoalberghini2040 2 ปีที่แล้ว +7

    In next js you can dynamic import as well btw, and automatically imports it when needed

  • @TubularAnimator
    @TubularAnimator 2 ปีที่แล้ว +2

    I just subscribed with all notifications, liked, commented, and shared.
    I also watched the whole video.
    It was enjoyable to consume.

  • @will_abule
    @will_abule 2 ปีที่แล้ว +2

    You're videos sometimes has perfect timing

  • @sguptzz
    @sguptzz 2 ปีที่แล้ว +3

    I love 1% code coverage man

  • @cool_scatter
    @cool_scatter 2 ปีที่แล้ว +27

    I had no idea vite could do this! Very useful

    • @thekwoka4707
      @thekwoka4707 2 ปีที่แล้ว +1

      It does it from using esbuild under the hood.

    • @CathalMacDonnacha-t8h
      @CathalMacDonnacha-t8h ปีที่แล้ว

      @@thekwoka4707 Rollup is what is used for production.

  • @TubularAnimator
    @TubularAnimator 2 ปีที่แล้ว +2

    I just subscribed, liked, commented, and shared. I also watched the whole video.

  • @3dilson
    @3dilson 2 ปีที่แล้ว +2

    are you in my house?
    I'm literally working in a project with vite using the react template and firebase
    And i had the exact same problem 🤯
    thank you so much for the amazing content

  • @desirechiduku964
    @desirechiduku964 2 ปีที่แล้ว +2

    Jeff must have a place among the programming Deities 🔥🔥

  • @bacon4life
    @bacon4life 2 ปีที่แล้ว

    Im so glad I work on the backend

  • @re.liable
    @re.liable 2 ปีที่แล้ว +1

    Really want to get started with Vite now

  • @codingperks
    @codingperks 2 ปีที่แล้ว +11

    Hi! Like the idea of this channel

  • @anonyme3029
    @anonyme3029 2 ปีที่แล้ว

    every video i learn something new🔥

  • @sergiomorenosuay3030
    @sergiomorenosuay3030 2 ปีที่แล้ว

    I'm loving these videos

  • @rutulpatel9433
    @rutulpatel9433 2 ปีที่แล้ว

    Never knew this channel existed Jeff :(

  • @mooshy5944
    @mooshy5944 2 ปีที่แล้ว

    I’m the lead at the company I work and that hangover clip had me rofln’

  • @StephenGillie
    @StephenGillie 2 ปีที่แล้ว +2

    A benefit to browser-side frameworks is that the whole package is very easy to cache. Why load anything at all? Offering Overview is 676 bytes per page load after the first load, and could be slimmed down more by moving the inline JS back to its own file.

  • @ahmetcanaksu6821
    @ahmetcanaksu6821 2 ปีที่แล้ว

    Im loving this channell

  • @AV_YOUTUBE_202X
    @AV_YOUTUBE_202X 2 ปีที่แล้ว +4

    I used to wonder why people did _"code golf"_ exercises. Now I know why. A little _"code golf"_ is something more people should practice. You'd be surprised how few bytes may actually be necessary to implement your functionality.

    • @4.0.4
      @4.0.4 2 ปีที่แล้ว +1

      As someone who's code golfed a bit, small does not usually mean faster. But I do agree Javascript taking 500k+ is absolute nonsense.

    • @AV_YOUTUBE_202X
      @AV_YOUTUBE_202X 2 ปีที่แล้ว

      @@4.0.4 For sure smaller is not faster - loop unrolling for example - In theory the fastest program would just be one giant map of inputs to outputs, very large in size, very fast to execute.
      Yet smaller programs are typically easier to understand and reason about, and are often more flexible in terms of adding features or reusability. Those qualities lead to faster overall systems in the long run, because if individual code modules aren't flexible and easy to reason about, the entire system will eventually get slow due to compromises in its design...
      More people should do code golf so they can get positive experience with that "flavor" of programming.

  • @ioneocla6577
    @ioneocla6577 2 ปีที่แล้ว +3

    JS devs : nooooo 500kb is too much !!1!1!1!1!!!!
    Balzor devs : wow i managed to shrink it down to 10mb

    • @Dev-Siri
      @Dev-Siri 2 ปีที่แล้ว

      Is it Balzor or Blaze?

    • @ioneocla6577
      @ioneocla6577 2 ปีที่แล้ว +1

      @@Dev-Siri blazor. The c# webassembly spa framework

    • @Dev-Siri
      @Dev-Siri 2 ปีที่แล้ว

      @@ioneocla6577 oh ok

  • @Landon_S2
    @Landon_S2 2 ปีที่แล้ว +18

    Just wondering, don't dynamic imports eliminate the bundler's ability to statically analyze what code is used and therefore eliminate tree shaking for that entire import? From my understanding of tree shaking, it only works for es2015 style imports to statically analyze what is used and eliminate dead code from the bundle. If you are only using one functionality from firebase, tree shaking should only include the code for that one functionality, but if you import it dynamically then it has to include the entire package code in your final bundle. Am I missing something here?

    • @AdarshMadrecha
      @AdarshMadrecha 2 ปีที่แล้ว

      I was just wondering the same.

    • @wlockuz4467
      @wlockuz4467 2 ปีที่แล้ว

      Yeah was thinking the same thing, unless its smart enough to recognise every import statement I think tree shaking wouldn't work with dynamic imports.

    • @brianevans4
      @brianevans4 2 ปีที่แล้ว +2

      the import() function returns a promise containing the entire module, if you only want one part of it you do import('firebase').then(f=>f.onUpdate) for example, but its still requested the entire firebase module, so you may end up shipping more code to the browser. Unless Vite has a smart way of figuring out what you actually use and then removing dead code??

    • @krisantuswanandi
      @krisantuswanandi 2 ปีที่แล้ว

      haven't tried it yet but i guess you can static import into a file than dynamic import that file. also for some packages, you can pas specific path into dynamic import like import('package/path/to/function') instead of import('package')

    • @ra2enjoyer708
      @ra2enjoyer708 2 ปีที่แล้ว

      Well clearly firebase wasn't tree-shakeable in the first place so it's a moot point for this particular circumstance.

  • @aliasgar.burhani1099
    @aliasgar.burhani1099 2 ปีที่แล้ว +4

    Only thing I don't like about vite is that it still doesn't support react context or any other state management ... would be glad to know the solution of this issue

    • @lucasjames8281
      @lucasjames8281 2 ปีที่แล้ว +2

      the solution is to stop using react

  • @pixeledcode
    @pixeledcode 2 ปีที่แล้ว +2

    Ofcourse when I'm struggling with huge bundle size, Fireship uploads a video.
    Next video on tree shaking!

  • @dominicanfrankster
    @dominicanfrankster 2 ปีที่แล้ว +1

    I remember going through code splitting hell on my website. I managed to get the 100 on pagespeeds, but lort was it a pain. I wish Vite was around then. Astro islands are doing it for me right now as I rebuild.

  • @thedelanyo
    @thedelanyo 2 ปีที่แล้ว +17

    Frameworks like Sveltekit is making it possible to run your most heavy deps on the server (firebase-admin comes here), so authentication and some stuffs can be run on the server and in addition to your techniques,, there's a possibility of small smart client 🤓 🤓

  • @aryantirkey1744
    @aryantirkey1744 2 ปีที่แล้ว

    1:40 thanks I'm only aware of the route level

  • @parthipankalayini8
    @parthipankalayini8 2 ปีที่แล้ว +1

    New Next js logo 🤩😅

  • @cpemby
    @cpemby 2 ปีที่แล้ว

    Vite is the move

  • @noherczeg
    @noherczeg 2 ปีที่แล้ว

    Stock Rollup can do the same. You don't need Vite for this.

  • @wingmann3632
    @wingmann3632 2 ปีที่แล้ว +1

    omaigod zet iz sou smart

  • @MrErickAnderson
    @MrErickAnderson 2 ปีที่แล้ว

    Waiting for the programmer humour channel to be created.

  • @bibahbibah5108
    @bibahbibah5108 2 ปีที่แล้ว

    in react u can do it with lazy import whit out vite

  • @komakaze1
    @komakaze1 2 ปีที่แล้ว

    Did the video give the impression that only Vite could do dynamic imports? Or am I missing some nuance? I do like Vite, just curious.

  • @jonesmartins
    @jonesmartins 2 ปีที่แล้ว +1

    If lazy loading is so much better, should you use it everywhere?

  • @renz2965
    @renz2965 2 ปีที่แล้ว

    thanks helpful vid

  • @nightfury9698
    @nightfury9698 2 ปีที่แล้ว +3

    Angular does this ages ago..using lazy loading..I think Angular is far far more advanced than the all other js framework and for some unknown reason it is also most underrated js framework.

    • @RamoFX
      @RamoFX 2 ปีที่แล้ว

      Because it is by far more complicated, that is the reason

    • @krazymeanie
      @krazymeanie 2 ปีที่แล้ว

      I think Angular is just a bit too complicated when it doesn't need to be.

    • @nightfury9698
      @nightfury9698 2 ปีที่แล้ว

      Learning curve of Angular is slow compared to other framework, that part I agree. But once you used to the framework, it is hard to love any other framework.

  • @ikarusasas
    @ikarusasas 2 ปีที่แล้ว +1

    Backend bundles? Anyone? I really like microbundle for that purpose but it is slow af. SWC and Rust/Go based tooling is what I hope to use one day

  • @ezra3871
    @ezra3871 2 ปีที่แล้ว

    Thanks

  • @tender.branson
    @tender.branson 2 ปีที่แล้ว +1

    Angular has lazy routed modules.

  • @moitp2
    @moitp2 2 ปีที่แล้ว +3

    Meanwhile Angular : you can do that for quite a while now :p

    • @MrEnsiferum77
      @MrEnsiferum77 2 ปีที่แล้ว

      And u have already observables (which u don't need to worry about ssr crap) what is famous for some time now, because of solidjs and telling liberal kids, hey kids, see, solidjs is react, but fixed, oh god

  • @pokefreak2112
    @pokefreak2112 2 ปีที่แล้ว +3

    The best way to get a smaller bundle is to write less js. Occam's razor 😉

    • @IainSimmons
      @IainSimmons 2 ปีที่แล้ว

      Kind of... if you wrote everything yourself instead of relying on 3rd party libraries, that might be possible, especially avoiding ones that can't be tree-shaken like Moment (as mentioned in the other video about relative dates). But that's obviously more work than most are willing to put in.
      And if your site is mostly static, then yeah, something like Astro could really help.
      Also we used to do a lot of things with JavaScript (especially jQuery), that can either be done with native HTML elements and/or CSS.
      So, I definitely agree with you, but it's not always that simple!

    • @Tony-cm8lg
      @Tony-cm8lg 2 ปีที่แล้ว

      Write less JavaScript and use Blazor. Problem solved lol

    • @pokefreak2112
      @pokefreak2112 2 ปีที่แล้ว

      ​ @Iain Simmons Libraries are fine but they should be provided as (public domain) starter templates, not black boxes to pile your own hacks on top of. Layered architectures are insanely overrated.
      In my personal experience library spam makes it fast to get a project going but dev time exponentially increases over the lifetime of the app. When you control the entire codebase it stays linear.

  • @avjvfx6484
    @avjvfx6484 2 ปีที่แล้ว

    Yesssss!!!

  • @muhamadaminibragimov5096
    @muhamadaminibragimov5096 ปีที่แล้ว

    Webpack also can lazy load)

  • @danser_theplayer01
    @danser_theplayer01 2 หลายเดือนก่อน

    Can't you load stuff into frontend partially? Half the job board postings want me to use React, and that's a thing it can do.

  • @hakuna_matata_hakuna
    @hakuna_matata_hakuna 2 ปีที่แล้ว

    Maybe review yet another frontend framework , like nextja but uses vite as the build tool

  • @abdurrasheed3596
    @abdurrasheed3596 2 ปีที่แล้ว

    Is there any way to get same result in Angular?

  • @0xtz_
    @0xtz_ 2 ปีที่แล้ว +1

    Any fast way to create a React app without the ` create-react-app ` ????

    • @thekwoka4707
      @thekwoka4707 2 ปีที่แล้ว

      Sure
      npm init pett-app

    • @Dev-Siri
      @Dev-Siri 2 ปีที่แล้ว

      Use Vite
      npm init vite app-name
      Then a drop-down will appear, choose react

    • @Vantivify
      @Vantivify 2 ปีที่แล้ว

      npm create vite@latest my-app -- --template react

    • @0xtz_
      @0xtz_ 2 ปีที่แล้ว +2

      @@Dev-Siri thanks 👌

    • @0xtz_
      @0xtz_ 2 ปีที่แล้ว +2

      @@Vantivify nice 👌 thanks

  • @hussainbharmal5998
    @hussainbharmal5998 2 ปีที่แล้ว

    Still haven't finished watching the video... Can this be done with angular+firebase?

    • @catholic_zoomer_bro
      @catholic_zoomer_bro 2 ปีที่แล้ว +2

      This is an app that uses vite, I think you can use vite with angular but I'm not sure

  • @ThanHtutZaw3
    @ThanHtutZaw3 2 ปีที่แล้ว

    Why I have to wait 4s to get data from Firestore in React. It is react problem or Country too far Problem?

  • @codedusting
    @codedusting 2 ปีที่แล้ว

    Can this be used in existing Nextjs project?

    • @bpuzoni
      @bpuzoni 2 ปีที่แล้ว +1

      Not using Vite, but you can take a look at NextJS Dynamic Import

  • @pixiedev
    @pixiedev 2 ปีที่แล้ว

    Any tips for nuxt 3 #fireshipio

  • @Cyranek
    @Cyranek 2 ปีที่แล้ว +3

    too much work. make it a pwa and force the user to download everything. not my problem. 😎

  • @jgarzarebel2631
    @jgarzarebel2631 2 ปีที่แล้ว

    ❤🌟

  • @danilobassi8
    @danilobassi8 2 ปีที่แล้ว

    God = Evan You

  • @Victor_Marius
    @Victor_Marius 2 ปีที่แล้ว

    Wait....what! Isn't firebase used for databases? Why would you use it on the client side? Isn't that a security concern? Accessing the database directly from the client side??

  • @BirdTho
    @BirdTho 2 ปีที่แล้ว

    There is only one God.

  • @jomy10-games
    @jomy10-games 2 ปีที่แล้ว +2

    Everybody loves vite so much, but their docs are so aweful. I must be missing something

    • @komakaze1
      @komakaze1 2 ปีที่แล้ว +1

      I love Vite too, but agree the docs could be improved, particularly for beginners, and for a wider variety of tech stacks e.g. when you have a Umbraco CMS involved, or e11ty, Publii, Handle bars, different directory structures. Etc.

  • @atalocke
    @atalocke 2 ปีที่แล้ว

    KiB is kibibytes

  • @Saharia_Shihab
    @Saharia_Shihab 2 ปีที่แล้ว

    Make a video on own Virtual DOM.

  • @miauuuuofcat4535
    @miauuuuofcat4535 2 ปีที่แล้ว

    By now I’m a chunk 😘

  • @fateriddle14
    @fateriddle14 2 ปีที่แล้ว

    wait, what is this channel? If it's still fireship and still short videos, what's the word beyond for?

    • @paupertim5819
      @paupertim5819 2 ปีที่แล้ว

      He made a video explaining the difference in channel goals to keep channels in scope.
      First channel for basic overviews and news, second channel for a little more about principals and beyond news and brief overviews.

  • @xBZZZZyt
    @xBZZZZyt 2 ปีที่แล้ว +1

    solution: don't use bloated libraries

  • @fishplayer6320
    @fishplayer6320 2 ปีที่แล้ว

    Can't for a qwik video

  • @4.0.4
    @4.0.4 2 ปีที่แล้ว

    At some point you have to wonder what kind of functionality requires so much Javascript.

    • @physikus7888
      @physikus7888 2 ปีที่แล้ว

      The problem are often third party libraries without tree-shaking possibilities. Sure, you could write anything by yourself, but sometimes you just want to plug in some pre-made alternatives and basically have no other choice then to accept the bundle size.

  • @frittex
    @frittex 2 ปีที่แล้ว

    14

  • @nikolaandreev__
    @nikolaandreev__ 2 ปีที่แล้ว

    Kak e brat

  • @azedev
    @azedev 2 ปีที่แล้ว +3

    First
    (Please Pin)

  • @thes7450
    @thes7450 2 ปีที่แล้ว +3

    First
    (Don't pin the guy who wants to be pinned, jk)

  • @moltony
    @moltony 2 ปีที่แล้ว

    among the

  • @ropoxdev
    @ropoxdev 2 ปีที่แล้ว

    Yeah it’s not cool but if it’s so bad I don’t want it anymore lol it’s not a big mess anymore it’s just me and I just need to know lol what do it do lol I think I can get a little bit more like that lol lol I don’t know what to say but I’m still trying lol I just need a lot more help with my life lol lol I don’t think

    • @ropoxdev
      @ropoxdev 2 ปีที่แล้ว

      (generated with automatic apple keyboard)

    • @ropoxdev
      @ropoxdev 2 ปีที่แล้ว

      And don’t ask why here. I’m bored

  • @freeideas
    @freeideas 5 หลายเดือนก่อน

    Why do you need so much JavaScript? In a webpage? My suspicion is that instead of writing 20 lines of plain old Java script? you are using hundreds of thousands of lines of libraries and frameworks because it’s cool

  • @johnmukendi7650
    @johnmukendi7650 2 ปีที่แล้ว

    please give us your instagram id for further references,doubts and for clarification..

  • @Tonaldo90
    @Tonaldo90 2 ปีที่แล้ว

    Is this channel just your way to promote Firebase? If really starts seems like that 🤨🤨

  • @andrewgibson8794
    @andrewgibson8794 2 ปีที่แล้ว

    Easy. Just don't bundle.

    • @Dev-Siri
      @Dev-Siri 2 ปีที่แล้ว

      (⁠・⁠o⁠・⁠)

  • @dellavita3463
    @dellavita3463 2 ปีที่แล้ว

    Maybe bundled size is not that matter, Sometime your bundled size for all of your apps smaller than your single image in your site 😂

    • @ra2enjoyer708
      @ra2enjoyer708 2 ปีที่แล้ว

      Images are literally binary arrays, it's very easy to load them and the browsers do it off-thread in the first place. JS bundles on other hand have to be fetched, parsed, interpreted, then all sync and async side-effects in them ran. And side-effects can load other modules too, which means you can have several scripts going through these stages at once, all on the single thread.

  • @kubak3381
    @kubak3381 2 ปีที่แล้ว +1

    The best thing about it is that these days you can get away with having 10MB js file that's needed for a website to load and it still will work perfectly fine and the users won't notice any difference so pushing to decrease the file sizes is completely pointless. A 1MB decrease for example is nothing.

    • @IainSimmons
      @IainSimmons 2 ปีที่แล้ว +1

      Not everyone has super fast broadband internet, and if you use your website for your business, your users will notice, will care, and will not stick around.

    • @kubak3381
      @kubak3381 2 ปีที่แล้ว +1

      @@IainSimmons Not really. An incredibly small percentage of users have such a slow internet that cannot handle even 50MB per webpage
      Edit: and that's still a large size for even an unoptimized website

    • @komakaze1
      @komakaze1 2 ปีที่แล้ว +1

      Some more things to watch out for - Mobile users don't always get smooth connections, so that extra 1mb could break when they go indoors, in elevators, in crowds where networks come under pressure, rural/regional areas that have slower internet, or have lower end devices that may not handle things so well.

    • @kubak3381
      @kubak3381 2 ปีที่แล้ว +1

      @@komakaze1 users that use mobile devices are not "serious", as in - if something breaks for a user that uses a mobile device it'll be "no biggie". If an application is mission critical a user is going to be using it on a PC, or at least a laptop

  • @anj000
    @anj000 2 ปีที่แล้ว

    Or... stop using big unnecessary frameworks and libraries.
    Web development is really bloated and we need to move it into some kind of diet. Stop using over complicated dependencies just because of their marketing bullshit and do things yourself.

  • @ghafoor2657
    @ghafoor2657 2 ปีที่แล้ว

    Complicated

  • @DDrVadik
    @DDrVadik 2 ปีที่แล้ว

    FYI - kib is not kilobytes, it is kibibyte :) en.wikipedia.org/wiki/Kilobyte

  • @iAbhinavSinghal
    @iAbhinavSinghal 2 ปีที่แล้ว

    Can angular 🫣 do this?