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...
You can check out the following topic on behavior of different browsers to handle 301 redirect: Client Web Browser Behavior When Handling 301 Redirect
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:
- Prettify URLs
- Ensure Link equity
- Resolve canonical issue.
精彩评论