开发者

Can I use a 301 redirect for included external javascript files?

I am trying to clean up some files on a website, one task being to collate all references to jquery to a singular file.

Yes, it's a large site with multiple developers and some standards have not been followed resulting in the current situation where there 开发者_开发知识库are various versions of jquery referenced.

What I have tried to do is create a 301 redirect for these files to point to a single version.

eg: <script type="text/javascript" src="/someurl/js/jquery-1.4.4.min.js"> should end up pointing to /someurl/js/jquery-core.min.js

I have tried to do this but it appears to fail to load the new file and jquery does not exist, my net panel shows that the original file has a 301 on it and I can see the reference to the new one, however the "response" tab is empty.

Is it possible to use a 301 redirect in this way?

Thanks for any suggestions / feedback

p.s I know there are better ways to reference jquery etc but large company process and red tape stand in my way from doing this any other way


When a browser loads the script from the src attribute, it should follow all redirection links, in the same method it retrieves html, images, stylesheets, etc. So the use case you've provided should work.

But since it's not working for you, you have got a couple options to resolve your problem.

Use fiddler or a similar debugging proxy to see what's going on between your browser and the server. Perhaps the 301 is malformed, or perhaps the mime-type is misconfigured, it could be any number of things. Troubleshoot it the same way you'd troubleshoot any other issue where the browser isn't following redirects.

Or... instead of using redirects, you can use mod_rewrite (or a similar server-side URL rewriting tool) to modify the request for a particular version of a script to your canonical version.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜