Take the 2-minute tour ×

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...

share|improve this question
maybe you should go straight with https –  Ibu May 31 '11 at 2:56
I think it will. Script requests are just regular browser HTTP requests (which will follow redirects). Unfortunately, I can't really cite anything to support this. –  Cristian Sanchez May 31 '11 at 3:08
add comment

2 Answers

up vote 2 down vote accepted

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.
share|improve this answer
add comment

You can check out the following topic on behavior of different browsers to handle 301 redirect: Client Web Browser Behavior When Handling 301 Redirect

share|improve this answer
+1 I don't think the browser cares whether the url points to a html/php/js etc etc etc page. But for the life of me i haven't found any documentation to say that ... yet. –  James Khoury May 31 '11 at 3:12
add comment

Your Answer


