简体   繁体   English

图片需要一段时间才能在网站上加载?

[英]pictures take a while to load on website?

I made a similar post a couple of hours ago but it was really poorly written and lazy. 几个小时前我发了一篇类似的帖子,但写的很糟糕,很懒。 So I'm re posting as I ruined that post but still need help. 所以我发帖,因为我破坏了那个帖子,但仍然需要帮助。 Sorry to anyone who read the first post it was awful. 对于阅读第一篇文章的人来说,这太可怕了。

Here's my website: 这是我的网站:

http://top-drawer.net/artists.html http://top-drawer.net/artists.html

When I view my website on a new browser the images take noticeably long to load. 当我在新浏览器上查看我的网站时,图像显然需要很长时间才能加载。 The images I'm talking about are the ones seen on the artists page(linked above) as well as the images on the idividual artist pages( http://top-drawer.net/artist-1.html ). 我正在谈论的图像是在艺术家页面(上面链接)上看到的图像以及在个人艺术家页面上的图像( http://top-drawer.net/artist-1.html )。

The length of time for the images to load into place looks very unprofessional when I'm trying to show someone the website. 当我试图向某人展示网站时,图像加载到位的时间长度看起来非常不专业。

What is causing this load time? 是什么导致了这个加载时间? and how would I fix this problem? 我该如何解决这个问题呢?

just for information I'm currently viewing my work in chrome. 仅供参考我目前正在查看我在chrome中的工作。 Any answer will be very much appreciated. 任何答案都将非常感谢。 But if possible it would be really help for me if you could explain the logic to your answers as I want to really understand/learn not just copy your code. 但是如果可能的话,如果你能解释你的答案的逻辑,那么对我来说真的很有帮助,因为我想要真正理解/学习不只是复制你的代码。 But of course thanks to anyone who takes the time to post an answer. 但当然感谢任何花时间发布答案的人。

While your images have been resize with CSS to appear small they are actually still quite large: 虽然您的图像已经使用CSS调整大小以显示小,但它们实际上仍然非常大:

http://top-drawer.net/images/bennyPalmer/2.jpg (1280x849, nearly 300KB) http://top-drawer.net/images/bennyPalmer/2.jpg(1280x849 ,近300KB)

This means they will take longer to download. 这意味着下载需要更长时间。 For the thumbnails, create new images that are the size you'd like and use those instead. 对于缩略图,请创建您想要的大小的新图像,然后使用它们。 At the moment you have around 3MB of images on your homepage. 目前,您的主页上有大约3MB的图像。

You need to optimize your images. 您需要优化图像。 Techniques include: 技术包括:

  • Compressing the images (using lossy compression like jpg over lossless compression like png) 压缩图像(使用有损压缩,如jpg,无损压缩,如png)

  • Loading lower quality images at first as placeholders and then load higher res ones in the background and replace them when they load 首先将较低质量的图像作为占位符加载,然后在后台加载较高质量的图像并在加载时替换它们

  • Using compression for requests (this is in addition to compressing the images themselves) 对请求使用压缩(除了压缩图像本身之外)

  • Using images without an alpha channel (they're going to be bigger if they have one) 使用没有alpha通道的图像(如果有的话,它们会更大)

  • Loading images of exactly the size you need. 加载完全符合您需要的尺寸的图像。 Resizing on the client side is really expensive! 在客户端调整大小非常昂贵!

  • Eliminate image metadata such as geo information (it takes up space and makes your images bigger) 消除图像元数据,例如地理信息(占用空间并使图像更大)

For more details I'd highly recommend this blog post by google: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/image-optimization?hl=en . 有关详细信息,我强烈推荐谷歌发布此博客文章: https//developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/image-optimization?hl = en

As the other answers are suggesting to reduce the size of the image, following are some online utilities which will help you : 由于其他答案建议减少图像的大小,以下是一些在线实用程序,它们将帮助您:

  1. http://www.reduceimages.com/ http://www.reduceimages.com/
  2. http://jpeg-optimizer.com/ http://jpeg-optimizer.com/
  3. http://www.picresize.com/ http://www.picresize.com/
  4. http://www.imageoptimizer.net/Pages/Home.aspx http://www.imageoptimizer.net/Pages/Home.aspx

You could try using a PHP page to resize the images on the spot. 您可以尝试使用PHP页面在现场调整图像大小。 For example you could use the following file structure to help: 例如,您可以使用以下文件结构来帮助:

 Document Root
 - img
 - - 1.png
 - - 2.png
 - - 3.png
 - - resize.php
 - index.php

Anytime you reference an image in index.php , use /img/resize.php?file=1.png&size=(Size Syntax Of Your Choice) . 无论何时在index.php引用图像,请使用/img/resize.php?file=1.png&size=(Size Syntax Of Your Choice) Within the PHP file, get the contents of the file and use PHP's resizing methods (or, better still: this ), then once you have got the new file; 在PHP文件中,获取文件的内容并使用PHP的调整大小方法(或者更好的是: 这个 ),然后获得新文件; use readfile to 'echo' the new resized file. 使用readfile来“回显”新调整大小的文件。 There is a lot of different ways you can go about this, If you don't know PHP tell us; 有很多不同的方法可以解决这个问题,如果你不知道PHP告诉我们; and I'll make it for you. 我会为你做的。

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

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