Rails 似乎为该页面提供两次服务 [英] Rails seems to be serving the page twice

查看:35
本文介绍了Rails 似乎为该页面提供两次服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在发出单页请求时在本地日志文件中看到的内容:

this is what I see in my local log file when I make a single page request:

Started GET "/" for 127.0.0.1 at Mon Apr 25 22:12:22 -0700 2011
  User Load (0.9ms)  SELECT "users".* FROM "users" WHERE ("users"."id" = 2) LIMIT 1
  Processing by PagesController#beta as HTML
Rendered pages/beta.html.erb within layouts/beta (16.2ms)
Completed 200 OK in 23ms (Views: 18.8ms | ActiveRecord: 7.7ms)


Started GET "/" for 127.0.0.1 at Mon Apr 25 22:12:23 -0700 2011
  User Load (0.6ms)  SELECT "users".* FROM "users" WHERE ("users"."id" = 2) LIMIT 1
  Processing by PagesController#beta as */*
Rendered pages/beta.html.erb within layouts/beta (17.9ms)
Completed 200 OK in 27ms (Views: 21.5ms | ActiveRecord: 6.6ms)

任何人都知道可能导致这种情况的原因是什么?加工线有趣吗?

Anyone have any ideas what could be causing this? the Processing line is interesting?

PagesController#beta as HTML
PagesController#beta as */*

这是什么意思?

推荐答案

我已经看到这种情况发生是因为 img 标签带有空白的 src 属性.为 imgscriptlink 或类似标签提供 srchref 属性="" 将解析到当前页面.因此,它会在尝试加载资产时再次尝试加载页面.它也可以在 CSS url() 属性或 AJAX 调用中.

I've seen this happen because of an img tag with a blank src attribute. Giving an img, script, link or similar tag a src or href attribute ="" will resolve to the current page. So it will try to load the page a second time as it tried to load the asset. It could also be in a CSS url() property or an AJAX call.

一种简单的判断方法是在您的 中临时放置类似 <base href="http://example.com"/> 的内容> 部分.这将为页面上的任何链接添加前缀,如果出现此类问题,这应该可以防止您的本地页面被调用两次.

One easy way to tell is to temporarily put something like <base href="http://example.com" /> in your <head> section. That will prefix any links on the page, which should prevent your local page from being called twice if it is that sort of problem.

我还看到一些浏览器扩展在单独的请求中查询页面.我已经通过 Web 服务器通知程序网络技术通知程序 适用于 Chrome 的扩展程序.尝试使用隐身"窗口或单独的浏览器,看看是否得到相同的结果.

I've also seen some browser extensions that query the page in a separate request. I've noticed this specifically with the Web Server Notifier and Web Technology Notifier extensions for Chrome. Try an "incognito" window or a separate browser and see if you get the same result.

这篇关于Rails 似乎为该页面提供两次服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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