3

If a.com loaded b.com/b.js as an external source. What is the domain within j.js? a.com, b.com or both?

2
  • ..........what? Where did j.js come from? Commented Aug 2, 2011 at 3:17
  • I believe j.js was supposed to be b.js. Commented Aug 2, 2011 at 3:20

2 Answers 2

1

JavaScript runs on the client side. If it looks at window.location it will see the current site - if that wasn't the case, all our JS from CDN's would point to the CDN's :)

Sign up to request clarification or add additional context in comments.

Comments

1

example.com can load any resource from any domain, but the code still has the same origin policy so it can only talk to example.com. You do not get special rights by loading it from the other domain.

Imagine if linking to a file would all of the sudden allow cross domain talking. If that was the case, any site could link to a JS file of a bank, email provider, etc and be able to make Ajax calls behind the scenes. Not good!

One great reason for loading content from another domain is cookies are not sent, meaning smaller payload. Also if you are loading from a CDN, people may already have the files in their browser's cache so no download time!

If you are looking to make cross domain calls, you either need to look at JSONP, CORS, or proxies.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.