Will JavaScript tag's src attribute follow HTT

2020-03-17 03:52发布

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

2条回答
时光不老,我们不散
2楼-- · 2020-03-17 04:44

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.
查看更多
够拽才男人
3楼-- · 2020-03-17 04:48

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

查看更多
登录 后发表回答