AMD module or NOT
I remeber like 1 year ago, Asyn Module Definition is so hot in javascript. Tools like RequireJS, SystemJS are widely used.
Even at my company, the part of the legacy system is built using Backbone and RequireJS.
Theoretically, it's good when it comes to a huge project when only part of the code will be used at run time.
Because the rest of the code is not being loaded at all.
Also, the file depency you defined at the top of the file is kinda of a 'dependecy injection' as well, very intuitive to use.
Although the total size loaded is reduced by using AMD, the user experience is not all that great.
Because if you need a new file, it still requires a round trip time to load and then be parsed by browser. This amount of time I would say is typically 100ms. Slow!
Some may say that the js file is actually cached by browser, so it might not actually load but just get from memory.
It's true, but even for the old fashioned 'single file' approach, js can also be cached. And for 'single file' approach, the need to load other files is non-existent, even better than AMD.
The only problem with 'single file' approach is that the initial load can be so slow if js files are too huge and not cachehd.
Working with Angular2, I see most people are going back to the 'single file' approach now.
Nowadays, with minify and gzip technologies, a 1mb js file can be easily compressed to less than 200kb.
With files of this size , the loading time is mostly network round trip time. There is no point in using AMD anymore.
posted on 2017-05-09 09:45 ayumiknight 阅读(111) 评论(0) 收藏 举报
浙公网安备 33010602011771号