Aaron Gibralter
Aaron Gibralter

Reputation: 4853

Will JavaScript tag's src attribute follow HTTP redirects in all browsers

Let's say, a javascript tag's src attribute points to a redirect:

<script src="http://foo.com/foo.js"></script>

where http://foo.com/foo.js is a 301 redirect to https://foo.com/foo.js...

Will all browsers successfully load the JS file? I've noticed it seems to work in Chrome, Firefox, Safari, and IE9... but I'm just curious if this is something that's in a spec or just random...

Upvotes: 8

Views: 7131

Answers (1)

a6hi5h3k
a6hi5h3k

Reputation: 681

Loading resources for a webpage (be it script source, image source or whatever) is agnostic to how browser fetches it for you (using HTTP protocol over TCP/IP).

The only thing to be aware of here is that browser makes two request to download one resource & provided that script calls are blocking in browser, so it is not advised to use this strategy for long. For the 3 very basic reason we use 301s are:

  1. Prettify URLs
  2. Ensure Link equity
  3. Resolve canonical issue.

Upvotes: 3

Related Questions