简体   繁体   English

Laravel 5.2-如何在所有内容加载之前呈现页面

[英]Laravel 5.2 - How to render page before all content load

I've another question about Laravel. 我还有一个关于Laravel的问题。

I've got gallery in my project which loads a lot of images (currently it's about 80 but it will still grow). 我的项目中有图库,该图库可以加载很多图像(目前大约有80张图片,但仍会增长)。 The way I'm loading images is easy - in controller I get all the records from photos table and just passing them to view. 我加载图像的方式很简单-在控制器中,我从photos表中获取所有记录,然后将它们传递给视图。 In view I have foreach loop which shows every image. 在视图中,我有显示每个图像的foreach循环。

The problem is that Laravel is probably caching the rendered page and then loads it. 问题在于Laravel可能会缓存呈现的页面,然后加载它。 It causes gallery page long lasting loading (now between 5-10 sec depends on server load). 这会导致图库页面长时间持续加载(现在取决于服务器负载在5到10秒之间)。

Am I right that it firstly caches the rendered page and then loads it? 我是对的,它首先缓存渲染的页面然后加载它吗? Will using faster caching package solve the problem? 使用更快的缓存包是否可以解决问题? Or is there any other way to speed up site loading? 还是有其他方法可以加快网站加载速度?

Thanks in advance! 提前致谢!

What you want goes beyond Laravel and the slow load time is due to the amount of time it takes for the client to download the images. 您想要的超出了Laravel,而缓慢的加载时间是由于客户端下载图像所花费的时间所致。 (Unless of course you are sending the images in base64 which would be quite strange in this case.) (除非您当然要在base64中发送图像,否则在这种情况下会很奇怪。)

Here is how others have solved this problem: 这是其他人解决此问题的方法:

  • Create thumbnails for all the images and full size images are viewed after a thumbnail link is clicked. 单击所有缩略图,然后为所有图像创建缩略图,然后查看完整尺寸的图像。
  • Use a JavaScript to load the images. 使用JavaScript加载图像。

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

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