调用 JavaScript 时在 FireFox 中使用 IIS URLRedirect 进行多重重定向

发布于 2024-12-03 11:43:31 字数 1785 浏览 0 评论 0原文

我遇到的问题仅发生在 Firefox 的后续版本中。 我已经检查了 fiddler 中常用的浏览器,它们的

表现都很好到目前为止......我有一个网站已移动到新的托管提供商。网站内容(图像、音频等)过去可以使用 IIS 中的虚拟目录在内容共享上获取。对 HTML 内容的引用是通过相对路径完成的,例如“/images/pic.gif”。

作为网站迁移的一部分,内容随后被移动到另一个 URL,因为我们不想将内容托管在 Web 代码所在的同一服务器上。 (造成这种情况的原因有多种,但不影响此问题)。这样我们就不必重新指向我们使用 IIS URL 重定向的内容(图像、音频)的所有现有引用 ( http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module)并设置下列的在应用程序的 web.config 中。

<rewrite>
  <rules>
    <rule name="Images">
      <match url="^/?images/(.*)$" />
      <action type="Redirect" url="http://data.xxxx.com/images/{R:1}?ref=1" />
    </rule>
  </rules>
</rewrite>

重定向工作正常,因为图像引用以 data.xxxx.com 为前缀,并且图像在网站上正常显示。如果我们使用 JavaScript 添加广告到网站,例如...

<script language="javascript">

if (window.adgroupid == undefined) {
window.adgroupid = Math.round(Math.random() * 1000);
}
document.write('<scr' + 'ipt language="javascript1.1" src="http://xxx.xxx.xxx/addyn/3.0/981/2185858/0/225/ADTECH;loc=100;target=_blank;key=key1+key2+key3+key4;grp=' + window.adgroupid + ';misc=' + new Date().getTime() + '"></scri' + 'pt>');
</script>

...它会使重定向发生两次。

firebugreferences

这只发生在 Firefox 中

如果我将 javascript 移至图像调用下方,则问题不会发生。

firebug引用没问题

我尝试过在javascript标签中使用defer="defer",但是广告将不会显示在页面上。

我检查了各种资源,但不明白为什么会发生这种情况,除了页面中 javascript 的位置之外,我们没有更改任何代码。

我需要减少对内容服务器的调用次数,因为我们是按每次调用付费的,因此我们拨打的任何多余调用都会给我们带来经济损失。

谢谢你的帮助

The issue I have only happens in the later additions of Firefox. I've checked the usual browsers in fiddler and they are behaving themselves

The story so far..... I have a website that has moved to a new hosting provider. The website content (images, audio etc...) used to be available on a content share using virtual directory within IIS. References to the content in HTML was done via relative paths e.g. "/images/pic.gif".

As part of the migration of the site, the content was then moved onto another URL as we didn't want to host the content on the same servers that the web code is on. (There are various reason for this but they don't affect this issue). So that we didn't have to re-point all the existing references to the content (images, audio) we used IIS URL Redirect ( http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module) and set the following in web.config for the app.

<rewrite>
  <rules>
    <rule name="Images">
      <match url="^/?images/(.*)$" />
      <action type="Redirect" url="http://data.xxxx.com/images/{R:1}?ref=1" />
    </rule>
  </rules>
</rewrite>

The redirects work fine as the image references are prefixed with data.xxxx.com and the images display on the site fine. If we add advertising to the site by using JavaScript such as...

<script language="javascript">

if (window.adgroupid == undefined) {
window.adgroupid = Math.round(Math.random() * 1000);
}
document.write('<scr' + 'ipt language="javascript1.1" src="http://xxx.xxx.xxx/addyn/3.0/981/2185858/0/225/ADTECH;loc=100;target=_blank;key=key1+key2+key3+key4;grp=' + window.adgroupid + ';misc=' + new Date().getTime() + '"></scri' + 'pt>');
</script>

...it makes the the redirect happen twice.

firebug references

This only happens in Firefox

If I move the javascript to below the image calls then the issue does not happen.

firebug references okay

I've tried using defer="defer" in the javascript tag, but the advertising then doesn't display on the page.

I've checked various resources and can't see why it's happening, we're not changing any code apart from the position of the javascript within the page.

I need to reduce the number of calls we're making to the content servers as we are being charged on a per call basis, so any surplus calls we make is hitting us financially.

Thanks for you help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

前事休说 2024-12-10 11:43:31

您看到的问题是 Firefox 中的图像缓存并不能很好地处理重定向(并且可能您正在阻止 HTTP 级缓存)。因此,在等待脚本时启动的图像预取和实际图像加载最终都会到达网络。

请参阅https://bugzilla.mozilla.org/show_bug.cgi?id=552605

The issue you're seeing is that the image cache in Firefox doesn't really handle redirects well (and presumably you're preventing HTTP-level caching). As a result the image prefetch that kicks off while waiting on the script and the actual image load both end up hitting the network.

See https://bugzilla.mozilla.org/show_bug.cgi?id=552605

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文