programsam / binkjs

Music archival site BINK, rewritten as a Node.js express app
0 stars 1 forks source link

Dynamically load JS when possible #67

Closed programsam closed 1 month ago

programsam commented 6 years ago

Right now there’s a decent amount of code that has to be downloaded from CDN just to be able to use the app.

$.getScript() is a new jQuery feature that makes it easy to dynamically add more scripts as necessary from CDN or elsewhere.

So the guiding principle here is don’t load a script unless they go to a page where that script will be needed. At minimum this includes script libraries for:

programsam commented 1 month ago

https://github.com/programsam/binkjs/blob/master/lib/scriptHolders.js handles loading the correct script tag. https://github.com/programsam/binkjs/blob/master/public/js/bink.js#L83-L109 actually dynamically loads them. Functions must be passed to wait until things are loaded: https://github.com/programsam/binkjs/blob/master/public/js/bink.js#L120-L122, and there's a setinterval that checks it periodically before proceeding. This is definitely finished.