Question

In my Javascript heavy Web app, I have some scripts that are loaded in the source HTML with tags, and others that I load as needed using jQuery's ajax method.

I am in the process of relocating most of my app's static assets to a CDN (I'm using AWS Cloudfront). My dynamic loads no longer work. The jQuery Ajax call:

$.ajax({
    url: url, 
    dataType: 'script',
    async: true,
    success: function (content) {
        ....

triggers the success function, but the content is empty.

I'm wondering if this is because such a request violates the Browser's security model for cross-site scripting. If that's the case, is there to load scripts dynamically from a CDN? Ahhh... I am NOT presently using a CNAME alias for the cloudfront host. Would doing so solve this problem?

Was it helpful?

Solution

You're right, it is the cross-site scripting security preventing this.

You're able to use the jQuery.getScript() method to load it from an external domain (or internal).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top