Learning material for professionals eager to explore the science behind building a successful online product

#ASKTHEINDUSTRY 17: Ship less JavaScript? I mean, really?

Yes, really! When I talk to people about this, the typical reaction I get is “Hey, if I knew how to do it without JavaScript I would!”

If you had a similar thought, you’re missing the point. Shipping less JavaScript is a technique, aimed to reduce the time spent by the browser parsing the code. Is has two fundamental goals:

  • To make your First Paint happen sooner
  • To make your app interactive (much!) sooner

As such, you don’t need to take it that literally. If you can’t find a way to replace your JavaScript with some CSS-only implementation, or by leveraging existing platform features, you still can — and should — ship less JavaScript upfront.

Ship the ABSOLUTE MINIMUM at first. Then asynchronously load other bits and pieces.

If you really need all that JavaScript, please ship it, but do it wisely. Ship the ABSOLUTE MINIMUM at first. Then asynchronously load other bits and pieces. However, be careful! Don’t fall in the trap of splitting your code in just two bundles: an initial really small one, and a huge one with all the rest. This will simply postpone the problem, since it will block the main thread anyway as soon as your code arrives. Split in as many bundles as it is reasonable, so not to block the main thread for too long at once.

I read each and every comment, and look forward to see what you think! Also, this piece is part of the #ASKTHEINDUSTRY project, which is a distributed interview to the web industry: you ask, I’ll answer, or find someone who can! Drop a comment if there is anything I can help you with!

Care to leave a comment? Drop down a line on the Twitters