News for hackers. Stuff that matters.
Re:Managing Async Dependencies with JavaScript by z3t4 on Saturday May 20, 2017 @03:35PM (#14383956)
You can use http push (link preload header) or prefetch to make the browser download all dependencies async. Then require the modules sync. when they are needed. The advantages with modules is that they can always be cached! You do not have to bundle or add compile steps. Just use sync. require. Here's an example require script: https://www.webtigerteam.com/webmodules/require.js
Re:Managing Async Dependencies with JavaScript by jhabdas on Sunday May 21, 2017 @09:03AM (#14387099)
Push has its use cases. It has its distinct drawbacks as well. Consider the scenario when you want to lazy-load a script based on a user action so you're not aggressively loading things the user might not need. You may also enjoy: https://www.smashingmagazine.com/2017/04/guide-http2-server-...
Re:Managing Async Dependencies with JavaScript by z3t4 on Sunday May 21, 2017 @03:14PM (#14388696)
It's up to the browser to optimize. What I've discovered so far is that push has low priority and that if a script is required while it's being downloaded (pushed), the browser (chrome) downloads it twice. The browser could however be smart about it and just make the required script top priority and only download it once. The browser could also parse the pushed scripts (chrome currently doesn't) if the cpu is idle. This opens up for modules on the web, like in Node.JS, but without the latency penalty. Also there is no need for the browser to pre-parse the scripts to look for modules when they are already pushed.