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

前端 未结 1 1499
忘掉有多难
忘掉有多难 2021-01-21 10:02

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

1条回答
  •  悲哀的现实
    2021-01-21 10:55

    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 讨论(0)
提交回复
热议问题