Skip to content

AJAX loading JS, CSS, and HTML

Having problems loading scripts and CSS when loading content with AJAX?

The solution is simple: Don’t have the JS or CSS in the pages you load up with JavaScript.
Instead, when you load up the HTML with your AJAX call, also call the scripts and CSS you need separately at the same time.

After including an AJAX call script like the awesome one here, use something like the following code for your links:

This simultaneously calls the .htm page as well as executes the .js and .css files.

Although this means that if you already have the JS and CSS included in the page you’re calling you will have to separate it from the HTML, (1) it will work now, and (2) separation of content from presentation and behaviour is a best-practice in any case.

To see more details of implementation, see a great demo here.

Be First to Comment

Leave a Reply