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){}
});
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With