Bartosz Goralewicz asked Martin Splitt of Google an interesting question. He asked if we should break out CSS and JavaScript files into smaller chunks of files or not. The answer from Martin is a long one but in short, it depends. :-)
It seems like using smaller chunks can help a bit with debugging issues and also with Google caching things but it can cause other issues. So if you do it, make your chunks reasonable and don't over do it. Bartosz summed it up on Twitter saying "It is good to have *reasonable* chunks but also - don't go crazy with deploying changes every few hours for all the files. It is better to only deploy changes to a single file that *needs* it, rather than change versions just for the sake of deployment?"
Here is the question:
2/2 ... harder for Google to process a heavy script as it creates a 0/1 scenario when you either render/index everything or skip it altogether. Question 1 is it correct 2 do you guys have heuristics/options to partially script/render a JS file (we would assume its not possible)?
β Bartosz GΓ³ralewicz (@bart_goralewicz) June 16, 2020
Here is his seven part answer:
The "skip" scenario isn't the main culprit, but you're close. There are two concerns for rendering a single large bundle:
β Martin Splitt at π‘π¨π (@g33konaut) June 17, 2020
- non-recoverable parsing or execution errors
- caching
1/?
3/? There are certain errors that can break parsing in which case the entire JS file might be impossible to execute. That's bad if it's 100% CSR.
β Martin Splitt at π‘π¨π (@g33konaut) June 17, 2020
During execution, certain errors can also bail entirely and you're in a bad place again.
5/? To be honest, I think that's more of a hypothetical scenario than a real world issue. But caching is a real concern that I do see in the wild. We cache aggressively and some people deploy changes often. That can go 2 ways.
β Martin Splitt at π‘π¨π (@g33konaut) June 17, 2020
7/? But if the bundle is split *reasonably* into smaller chunks, then this invalidation can be more fine-grained (along chunks) which is great for the users as well as us.
β Martin Splitt at π‘π¨π (@g33konaut) June 17, 2020
But here is a bit more:
I wouldn't. I would keep the old files around for a while, if I wanna be on the safe side.
— Martin Splitt at π‘π¨π (@g33konaut) June 17, 2020
Forum discussion at Twitter.