Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving .JS files to a CDN: How to manage AJAX requests?

I am thinking of moving my static .JS files to a CDN such as Amazon S3 for performance reasons. As my PHP files and mySQL DB remain on my primary hosting domain what is the best way to manage my JS AJAX requests if they are now cross domain?

Currently they look like this within my .JS file (with relative paths):

$.ajax({
type: "POST",
url: "/myNearbyPhpFile.php",
data: {data:someData},
success: function($r){}
});
like image 465
wilsonpage Avatar asked Feb 24 '11 23:02

wilsonpage


2 Answers

It's no cross-domain-issue if you use js-files from another domain.

The document and the ressource where you send yor request to matter, not the location of the js-file

like image 54
Dr.Molle Avatar answered Sep 23 '22 18:09

Dr.Molle


As long as the HTML file embedding the JavaScript files is on the same domain as the PHP/Python/whatever scripts called by the JavaScript you do not have cross-domain request. The only case where the actual location of the embedded file matters is CSS using relative URLs e.g. for images (those are relative to the CSS location, not the document location). But the Same-Origin-Policy doesn't apply to that anyway.

So: You don't have to do anything different.

like image 25
ThiefMaster Avatar answered Sep 23 '22 18:09

ThiefMaster