渲染完整页面而不是“渐进式” (使用struts 2/tiles)

发布于 2024-07-12 05:55:41 字数 2019 浏览 4 评论 0原文

有没有办法让struts 2(使用tiles)在将其发送到浏览器之前构建整个页面? 我不希望页面在浏览器中一次一小部分地“逐步”构建。

我试图解决的主要问题是,即使只有部分内容发生变化,Internet Explorer 7 也会闪烁/闪烁页面(Firefox 做得更顺畅)。

因此,如果我有一个页面包含:

HEADER

some content

FOOTER

并且“某些内容”区域仅在页面加载之间发生变化,那么 FOOTER 部分在用页脚的背景颜色填充之前仍然会闪烁白色背景。 我认为也许通过让 struts 发送完整的页面,它的加载速度足以消除“闪烁”。 现在,FOOTER 来自服务器的时间比之前的部分晚了一点,因此它会闪烁(在 Internet Explorer 中,Firefox 可以顺利显示页面)。

注意:这是网站的一个重要要求,使用 ajax 加载中间内容已经过时了(框架或其他“黑客”也是如此)。 该网站是使用 CSS 而不是表格布局构建的,也许我将不得不使用表格布局才能使其正常工作...

关于使用tiles 刷新参数: 我尝试过,但它不能按我的需要工作。 我需要整个页面的刷新参数。 我尝试过普通的 jsp 页面指令“autoFlush=false”,但它不起作用。 我在主模板页面(而不是在图块中)设置了此指令。

这是主模板的示例,它使用页眉、正文和页脚模板。 使用 Thread.sleep() 我添加的问题很容易发现。 页脚比页面其余部分晚 2 秒呈现。

  <body>
  <div id="container">
  <t:insertAttribute name="header" flush="false" />

  <div id="content"><t:insertAttribute name="body" flush="false"/></div>

  <div class="clear"></div>
  <% Thread.sleep(2000); %>
  <t:insertAttribute name="footer" flush="false" />
  </div>
  </body>

更新

感谢您的评论。 这个要求实际上几乎是合理的,因为这不是一个正常的网页,认为是嵌入式的。

但显然没有办法配置 IE 在延迟一段时间后开始渲染(比如 Firefox 有大约 100 毫秒的可配置延迟)?

我试图拦截 TilesResult,但 doExecute 方法是在整个内容显然被评估之前运行的,因此该方法在 jsp 被评估之前已经退出(我的 Thread.sleep() 测试)。 我想知道如何将整个响应呈现给字符串,然后将其一次性输出到浏览器。

我知道这并不是万无一失的,网络延迟等可能会影响到这一点,但如果我能够立即获得所有输出的响应,并且可能使用基于表格的布局(IE 可能仅在表格关闭后才呈现表格),这可能合理工作。

或者然后尝试将其切换到 Firefox,或者也许忘记这个小故障...

更新 2

这开始困扰我,所以我做了一些调查。 如果我有一个普通的 jsp 页面(没有图块),则缓冲起作用(使用 buffer 属性),因此,如果我有 Thread.sleep() ,如果页面大小低于缓冲区大小,则整个页面会在两秒后呈现。 但是,如果我在页面中使用图块(如上例所示),我无法同时渲染页面(我什至在所有图块模板/“组件”中包含页面指令,没有帮助)。 那么瓷砖可能会在某个地方刷新响应?

此外,“有问题的图块”是我的身体部分,其中包含 struts:form 标签。 我用普通的表单标签替换了它,它按照我想要的方式工作...

更新 3

好吧,似乎没有人知道tiles或struts标签的内部工作原理... 没什么大问题,因为这是一个非常具体的案例和要求。 我通过在应用程序前面使用 apache 作为代理,并使用 apache 的代理配置选项来指定一个大缓冲区来解决这个问题。 我会将其标记为已回答。

Is there a way to get struts 2 (using tiles) to build the whole page before sending it to the browser? I don't want the page to be build "progressively" in the browser one part at a time.

The main problem I'm trying to solve is that internet explorer 7 flashes/blinks the page even if only some of the content changes (firefox does this much more smoothly).

So that if I have a page with:

HEADER

some content

FOOTER

And the "some content" area only changes between page loads, the FOOTER part still flashes the white background before filling it with the background color of the footer. I tought that maybe by getting struts to send the complete page it would load fast enough to eliminate the "blinking".
Now the FOOTER comes from the server a little bit later than the parts before it and so it flashes (in internet explorer, firefox displays the page smoothly).

NB: this is an important requirement for the site, and using ajax to load the middle content is out (as are frames or other "hacks"). The site is built using CSS and not a table layout, maybe I will have to use a table layout to get it to work...

About using tiles flush parameter:
I tried that and it doesn't work as I need. I would need a flush-parameter for the whole page. I have tried the normal jsp page directive "autoFlush=false" but it didn't work. I set this directive on my main template page (and not in the tiles).

Here is an example from the main template, which uses header, body and footer templates. With the Thread.sleep() I added the problem is easy to spot. The footer renders 2 secs later than the rest of the page.

  <body>
  <div id="container">
  <t:insertAttribute name="header" flush="false" />

  <div id="content"><t:insertAttribute name="body" flush="false"/></div>

  <div class="clear"></div>
  <% Thread.sleep(2000); %>
  <t:insertAttribute name="footer" flush="false" />
  </div>
  </body>

UPDATE

Thanks for the comments. The requirement is actually almost reasonable as this isn't a normal web page, think embedded.

But apparently there is no way of configuring IE to start rendering after some delay (like firefox has a configurable delay of some 100ms)?

I tried to intercept the TilesResult but the method doExecute is run before the whole content is apparently evaluated, so the method has already exited before the jsp is evaluated (my Thread.sleep() test). I was wondering how I could render the whole response to a string and then output that all at once to the browser.

I know that this isn't foolproof and network delays etc may factor in this, but if I could get the response to output all at once and maybe use a table based layout (IE possibly renders the table only after the table closes) this could work reasonably.

Or then try to get this switched to firefox or maybe forget all about this little glitch...

UPDATE 2

This started to bother me so I did some investigation.
If I had a plain jsp page (no tiles) the buffering works (with the buffer attribute), so that if I had my Thread.sleep() there the whole page rendered after two seconds if the page size was below the buffer size.
But if I used tiles in the page (as in the example above) I couldn't get the page to render at the same time (I even included the page directive in all my tiles-templates/"components", no help). So tiles probably flushes the response somewhere?

Furthermore, the "problematic tiles" was my body-part, which contained a struts:form tag. I replaced it with a normal form-tag and it worked as I wanted...

UPDATE 3

Ok, nobody seems to know the inner workings of tiles or struts tags...
No big problem as this is a very specific case and requirement.
I worked around it by using apache as a proxt in front of the application, and using apache's proxy configuration options to specify a large buffer.
I'll mark this as answered.

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

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

发布评论

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

评论(2

断念 2024-07-19 05:55:41

如果您愿意,您可以在服务器端一次性发送所有页面数据(许多框架为了方便起见都会这样做),但网络的现实情况是页面数据不会立即全部到达,浏览器将在数据包到达时呈现它。 这对于响应能力来说是一件好事,即使您*在审美上希望页面一次显示全部内容。

您可以通过简化标记并使用 deflate 压缩来降​​低有效负载大小来尽可能减少延迟,这通常是值得做的事情。 另外,您还可以确保您不会遇到一闪而过的无样式内容。 但是您无法控制浏览器何时选择渲染,除非在 JavaScript 中完成这一切,否则会带来所有缺点(即使如此,浏览器可能会缓慢地重绘)。

(* - 或者你的客户/老板,如果他提出了这个“重要要求”,即你的网站以某种方式与网络上的其他页面不同。)

You can send page data all at once at the server end if you like (and many frameworks do that anyway for convenience) but the reality of networking is that it won't all arrive at once and the browser will render it as packets arrive. And this is a good thing for responsiveness, even if you* aesthetically would like the page to display all at once.

You can reduce the lag as much as possible by simplifying markup and using deflate compression to keep the payload size down, and that's a worthwhile thing to do in general. Plus you can make sure you're not hitting a Flash Of Unstyled Content. But you can't control when the browser chooses to render, short of doing it all in JavaScript with all the downsides that entails (and even then, the browser might redraw slowly).

(* - or your client/boss, if that's who has come up with this "important requirement" that your site somehow work differently to every other page on the web.)

蛮可爱 2024-07-19 05:55:41

您可以在图块组件上使用“flush”属性吗?

<tiles:insertAttribute name="body" flush="false"/>

此外,如果输出缓冲区变得太大,它无论如何都会刷新。 尝试增加缓冲区大小?

<%@ page language="java" buffer="500kb" autoFlush="false" %>

Can you use the "flush" attribute on the tiles components?

<tiles:insertAttribute name="body" flush="false"/>

In addition if the output buffer gets too big, it will flush anyway. Try increasing the buffer size?

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