Load CSS dynamically
CSS is loaded by creating a
element and attaching it to the
. They way that
elements are attached to the
head differs between browser but the code is fairly straight-forward.
Here is an example (make sure
to show the developer console).
Loading HTML is actually trivilial. All you need to to is fetch the HTML with
and replace the
an element in the DOM.
Loading JS is also fairly easy. Here is an example: source
Make sure to open the developer console.
These examples should work in all browsers. It took my quite a bit of testing
(Safari and Chrome).
- Browserify - I use browserify for
developing complex apps. It brings the NodeJS style of modules to browsers and
there is also a port of many of the NodeJS API.
- Traceur - ES6
- AMD - Has been around for a long time
and works well but there are better alternatives today.