admin管理员组

文章数量:1417070

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

<script src=".js"></script>

where .js is a 301 redirect to .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...

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

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

where http://foo./foo.js is a 301 redirect to https://foo./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 edited Feb 7, 2018 at 18:25 Yves M. 31.1k24 gold badges109 silver badges149 bronze badges asked May 31, 2011 at 2:51 Aaron GibralterAaron Gibralter 4,8733 gold badges37 silver badges50 bronze badges 4
  • 1 maybe you should go straight with https – Ibu Commented May 31, 2011 at 2:56
  • 1 You can check out the following topic on behavior of different browsers to handle 301 redirect: stackoverflow./questions/2666089/… – rachel Commented May 31, 2011 at 3:07
  • 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 Commented May 31, 2011 at 3:08
  • Duplicates stackoverflow./questions/6381100/… and stackoverflow./questions/6456095/… – Yves M. Commented Feb 7, 2018 at 18:24
Add a ment  | 

1 Answer 1

Reset to default 3

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.

本文标签: htmlWill JavaScript tag39s src attribute follow HTTP redirects in all browsersStack Overflow