JavaScript标记的src属性会在所有浏览器中遵循HTTP重定向吗? [英] Will JavaScript tag's src attribute follow HTTP redirects in all browsers

查看:125
本文介绍了JavaScript标记的src属性会在所有浏览器中遵循HTTP重定向吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,javascript标记的src属性指向一个重定向:

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

其中 http://foo.com/foo.js 是一个301重定向到 https:// foo.com/foo.js ...

所有的浏览器能否成功加载JS文件?我注意到它似乎可以在Chrome,Firefox,Safari和IE9中运行......但是我只是好奇它是一种规范还是随机的...



这里唯一要注意的是浏览器发出两个请求来下载一个资源&前提是脚本调用在浏览器中被阻止,所以不建议长时间使用此策略。我们使用301的3个非常基本的原因是:


  1. 美化网址

  2. 确保链接权益

  3. 解决规范问题。


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

解决方案

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.

这篇关于JavaScript标记的src属性会在所有浏览器中遵循HTTP重定向吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆