简体   繁体   English

为什么包含在 thymeleaf 布局中的图像需要很长时间才能显示?

[英]Why included images in a thymeleaf layout takes a long time to being displayed?

I am working on a java app, works fine and all, but at the frontend, I am using thymeleaf (first time I use it, moving on from primefaces).我正在开发一个 Java 应用程序,一切正常,但在前端,我使用的是 thymeleaf(我第一次使用它,从 primefaces 开始)。

What Ive noticed is that the page loads (working locally) pretty fast, as expected, since the information is not reelevant and no DB is being used by now.我注意到的是页面加载(本地工作)非常快,正如预期的那样,因为信息不相关并且现在没有使用数据库。

What surprises me is that the images load probably 2 seconds later, I have no idea why, they are stored locally on the app assets folder.令我惊讶的是,图像可能在 2 秒后加载,我不知道为什么,它们本地存储在应用程序资产文件夹中。

I am incluiding them this way:我以这种方式包括他们:

<img th:src="@{/assets/images/myimage.png}" />

Is there anyway to make it faster?有没有办法让它更快? (Of course, I will later set more memory to my JVM, but this sort of stuff shouldnt take that long...) (当然,我稍后会为我的 JVM 设置更多内存,但这种东西不应该花那么长时间......)

Any caching or faster ways?任何缓存或更快的方法?

I am using spring 4 mvc我正在使用 spring 4 mvc

Thanks.谢谢。

There are so many variable to this i am not going to list all of them but a few:这有很多变量,我不打算列出所有这些,而是​​列出一些:

  • Distance between Client and Server客户端和服务器之间的距离
  • Efficiency of your application您的应用程序的效率
  • Size of images图片尺寸
  • Browser and all extensions/plugins attached to it浏览器和所有附加到它的扩展/插件
  • Power of server服务器功率
  • Power of client machine客户端机器功率
  • Delivery method运输方式
  • Potential javascripts that manage loading of images管理图像加载的潜在 javascripts
  • Malware恶意软件

As mentioned there is a lot more that I haven't listed and it really is a process of elimination.如前所述,还有很多我没有列出,这确实是一个消除过程。

Some things we have on our application that avoids the delay in images include我们在应用程序中可以避免图像延迟的一些内容包括

  • server memory increase from 512 to 1024服务器内存从 512 增加到 1024
  • Changing location of server to a more local source将服务器的位置更改为更本地的源
  • changing the location from where the application is sourcing the images (faster raid disks)更改应用程序获取图像的位置(更快的raid 磁盘)
  • delaying full page display until everything is preloaded on client machine (look into Flash of Unstyled Content Fixes)延迟整页显示,直到所有内容都预加载到客户端计算机上(查看 Flash of Unstyled Content Fixes)
  • Performance improvements on web application itself Web 应用程序本身的性能改进

What you need to do is explore each option and start improving on it and eventually you will get the results you need.你需要做的是探索每个选项并开始改进它,最终你会得到你需要的结果。

Fyi if you want to avoid loading images from server have them hosted on a CDN for speed of transfer.仅供参考,如果您想避免从服务器加载图像,请将它们托管在 CDN 上以提高传输速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM