我可以使用301重定向包含外部JavaScript文件吗? [英] Can I use a 301 redirect for included external javascript files?

查看:99
本文介绍了我可以使用301重定向包含外部JavaScript文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试清理网站上的一些文件,其中一项任务是将对jquery的所有引用整理为单个文件。

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

是的,它是一个大型网站有多个开发人员和一些标准没有被遵循导致当前的情况,其中引用了各种版本的jquery。

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.

我试图做的是创建301重定向这些文件指向单个版本。

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

例如:< script type =text / javascriptsrc =/ someurl / js /jquery-1.4.4.min.js\"> 最终应该指向 /someurl/js/jquery-core.min.js

我试过这样做,但似乎无法加载新文件并且jquery不存在,我的网络面板显示原始文件上有301我可以看到对新的引用的引用,但是响应选项卡是空的。

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.

是否可以以这种方式使用301重定向?

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

感谢您的任何建议/反馈

Thanks for any suggestions / feedback

ps我知道有更好的方法可以引用jquery等,但是大公司流程和繁文缛节阻碍我做任何其他方式

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

推荐答案

当浏览器从src属性加载脚本时,它应该遵循所有重定向链接,在它检索html,图像,样式表等的同一方法中。所以用例你就是提供工作。

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.

使用 fiddler 或类似的调试代理来查看发生了什么浏览器和服务器之间。也许301格式不正确,或者mime类型可能是错误配置的,它可能是任何数量的东西。排除问题的方法与解决浏览器未遵循重定向的任何其他问题的方法相同。

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.

或者...而不是使用重定向,您可以使用 mod_rewrite (或类似的服务器端URL重写工具)将特定版本脚本的请求修改为规范版本。

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.

这篇关于我可以使用301重定向包含外部JavaScript文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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