为什么有些页面请求获取使用Safari和Apache 2.2.3的JavaScript /图像资源时挂起? [英] Why do some page requests hang when fetching Javascript/image assets using Safari and Apache 2.2.3?

查看:162
本文介绍了为什么有些页面请求获取使用Safari和Apache 2.2.3的JavaScript /图像资源时挂起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的一些的Ruby on Rails应用程序的用户的抱怨,页面请求偶尔会无限期挂起Safari浏览器下(一对夫妇已经下​​的Firefox注意到了这一点,但它是压倒性的Safari用户)。经过一番调查看来,这些请求都被我们的Rails应用程序送达正确和提取这是在HTML中引用图像资源(这是在同一台服务器上托管)时出现的窍门。

我们已经配置Apache以直接服务于图像资源并绕过性能Rails应用程序。我们还启用了文字/的JavaScript / CSS的资产gzip的COM pression。下面是我们的Apache虚拟主机配置中的相关设置 - 也许我们已经在这样这或许可以解释这些任意悬挂请求的方式配置此

  RewriteEngine叙述在#SSL在IE下的正确行为
SetEnvIf之后用户代理。* MSIE。*\\
    nokeepalive SSL-不洁关机\\
    降级-1.0动力响应-1.0SSLEngine的在
了SSLCertificateFile /etc/httpd/conf/ssl/_.mycert.com.crt
了SSLCertificateKeyFile的/ etc / httpd的/ conf目录/ SSL / _。 mycert.com.key
SSLCertificateChainFile /etc/httpd/conf/ssl/gd_bundle.crtRequestHeader集X_ORIGINAL_PROTOCOL的https
RequestHeader集X_FORWARDED_PROTO的https#重写指数检查静态
重写规则^ / $ /index.html [QSA]
重写规则^ /(图片|样式|的JavaScript |系统)/?(。*),$ 0[L]#重写检查Rails的缓存页面
重写规则^([^。] +)$ $ 1.HTML [QSA]#放气
AddOutputFilterByType DEFLATE text / html的文本/纯文本/ XML文本/ CSS文本/ JavaScript的应用程序/ x-的javascript
BrowserMatch ^ Mozilla的/ 4的gzip只-text / html的
BrowserMatch ^ Mozilla的/ 4 \\ .0 [678]无gzip的
BrowserMatch \\ bMSIE!无gzip的!用gzip只-text / html的ExpiresActive On配置
< FilesMatch\\(ICO | GIF | JPE G | PNG | JS | CSS?)$。>
  ExpiresDefault进入加1年
  标题附加缓存控制公
< / FilesMatch>

有没有人经历过类似的问题?

我们的Ruby on Rails的Web应用程序使用运行在红帽企业Linux 5。

mod_rails和Apache 2.2.3

更新:
现在我已经尝试删除以下块和问题仍然存在,所以看起来我们可以排除被这个问题expires头:

  ExpiresActive On配置
< FilesMatch\\(ICO | GIF | JPE G | PNG | JS | CSS?)$。>
  ExpiresDefault进入加1年
  标题附加缓存控制公
< / FilesMatch>


解决方案

我有一个引人注目的好时机现在我们的网站调试类似的问题。 Safari用户 - 但似乎只有那些在Mac上 - 会抱怨,我们的网站将挂起随机加载的页面。它通常出现挂在图像上 - 完成了3项2,等等 - 但后来我禁用缓存在Safari浏览器,JavaScript和CSS,你猜怎么着?该页面还悬挂着。

首先,在Safari缓存的注意事项。即使你有禁用缓存中的开发菜单中选择,并从野生动物园菜单中选择清空缓存,你还有基于RAM的缓存。这意味着,如果你真的想模拟一个空的缓存,你必须退出Safari每个请求或按住Option + Shift +,而pressing Reload按钮祷告到神-的选择按键。这花了我一段时间才能弄清楚,直到我想通了,我有一个很难再现一致的问题。

所以!没有JavaScript,CSS或图像,你怎么离开?不多,除了实际的HTML。这就是把我到是很可能的COM pression相关的事实。果然,关闭IIS 6.0中的COM pression导致页面加载瞬间。由于IIS 6.0不具有基于用户代理关闭COM pression的一种便捷方式,我用的投资者关系联合会(即网址重写ISAPI筛选器)重写的Accept-Encoding 头当它来自Safari浏览器:

 #Safari浏览器不能正确处理gzip的COM pression;我们把它关掉通过设置
#Q值为零自称为Safari浏览器的所有代理
的RewriteCond%{HTTP_USER_AGENT} Safari浏览器
。RewriteHeader的Accept-Encoding:*; Q = 0

这个问题似乎是,如果Safari浏览器接收静态COM pressed内容(也就是服务器发送的Content-Length 头),然后选择Safari交易它就好了。但是,若Safari正在接收动态COM pressed内容(也就是服务器在为响应由ASP.NET和内容长度被渲染,直到它的完成是不知道的,所以服务器发送转移-encoding:分块),那么Safari浏览器进入片状SIR-挂起-A-Lot的模式

为什么呢?我不知道。但是,这是我如何解决它。

Some of the users of our Ruby on Rails app have complained that page requests occasionally hang indefinitely under Safari (a couple have noticed it under Firefox, but it's overwhelmingly Safari users). After some investigation it seems that these requests are being served correctly by our Rails application and the hang occurs when fetching image assets (which are hosted on the same server) which are referenced in the HTML.

We have configured Apache to serve the image assets directly and bypass the Rails app for performance. We have also enabled gzip compression on text/javascript/css assets. Below are the relevant settings from our Apache Virtual Host configuration -- perhaps we have configured this in such a way which might explain these arbitrary hanging requests?

RewriteEngine On

# Correct behaviour of IE under SSL
SetEnvIf User-Agent ".*MSIE.*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

SSLEngine On
SSLCertificateFile /etc/httpd/conf/ssl/_.mycert.com.crt
SSLCertificateKeyFile /etc/httpd/conf/ssl/_. mycert.com.key
SSLCertificateChainFile /etc/httpd/conf/ssl/gd_bundle.crt

RequestHeader set X_ORIGINAL_PROTOCOL 'https'
RequestHeader set X_FORWARDED_PROTO 'https'

# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA] 
RewriteRule "^/(images|stylesheets|javascripts|system)/?(.*)" "$0" [L]

# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]

# Deflate
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

ExpiresActive On
<FilesMatch "\.(ico|gif|jpe?g|png|js|css)$">
  ExpiresDefault "access plus 1 year"
  Header append Cache-Control "public"
</FilesMatch>

Has anyone experienced a similar problem before?

Our Ruby on Rails web application runs using mod_rails and Apache 2.2.3 on RedHat Enterprise Linux 5.

Update: I have now tried removing the following block and the problem still persists, so it looks like we can exclude the expires header from being the problem:

ExpiresActive On
<FilesMatch "\.(ico|gif|jpe?g|png|js|css)$">
  ExpiresDefault "access plus 1 year"
  Header append Cache-Control "public"
</FilesMatch>

解决方案

I was having a spectacularly good time debugging a similar issue on our site today. Safari users--but seemingly only those on a Mac--would complain that our site would "hang" randomly while loading a page. It usually appeared to be hanging on an image--2 of 3 items completed, etc.--but then I disabled the cache in Safari, JavaScript, and CSS, and guess what? The page still hung.

First, a note on Safari caching. Even if you have "Disable Caching" selected in the "Develop" menu and have selected "Empty Cache" from the "Safari" menu, you still have a RAM-based cache. This means that if you REALLY want to simulate an empty cache, you have to quit Safari with each request or hold down the Option + Shift + Prayer-To-Deity-of-Choice keys while pressing the Reload button. This took me a while to figure out, and until I figured it out, I had a hard time consistently reproducing the issue.

So! Without JavaScript, CSS, or images, what do you have left? Not much, aside from the actual HTML. This is what turned me onto the fact that is was probably compression related. And sure enough, turning off compression in IIS 6.0 resulted in the page loading instantaneously. Since IIS 6.0 doesn't have a convenient way of turning off compression based on the user agent, I used IIRF (an ISAPI filter that rewrites URLs) to rewrite the Accept-Encoding header when it comes from Safari:

# Safari doesn't handle gzip compression properly; we turn it off by setting 
# the q value to zero for all agents identifying themselves as Safari
RewriteCond %{HTTP_USER_AGENT} Safari
RewriteHeader Accept-Encoding: .* *;q=0

The issue seems to be that if Safari is receiving static compressed content (that is, the server sends the Content-Length header), then Safari deals with it just fine. But if Safari is receiving dynamic compressed content (that is, the server is serving a response being rendered by ASP.NET and the content length is not known until it's done, so the server sends Transfer-Encoding: chunked) then Safari goes into Flaky Sir-Hangs-A-Lot Mode.

Why? I have no idea. But this is how I work around it.

这篇关于为什么有些页面请求获取使用Safari和Apache 2.2.3的JavaScript /图像资源时挂起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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