简体   繁体   English

是否可以通过浏览器开发工具查看浏览器正在使用哪个 srcset 图像

[英]Is it possible to see which srcset image a browser is using with browser developer tools

I've been trying to see which srcset image my browser is using via the browsers developer tools, but apart from using the.network tab to see which image it fetches i can't tell.我一直在尝试通过浏览器开发人员工具查看我的浏览器正在使用哪个srcset图像,但除了使用 .network 选项卡查看它获取的图像外,我无法分辨。

Using the.network tab would usually be fine, but sometimes I've noticed that it will fetch 2 image versions at different sizes, this would happen if one break point is at 600 and another at 900 and the browser was currently at 750px wide.使用 .network 选项卡通常没问题,但有时我注意到它会获取 2 个不同大小的图像版本,如果一个断点在 600 处而另一个在 900 处并且浏览器当前为 750 像素宽,则会发生这种情况。

(Ive tried this both on Chrome & FireFox, and it seems chrome will pull down both images in certain cases, but FireFox seems to only ever pull down one) (我在 Chrome 和 FireFox 上都试过了,在某些情况下 chrome 似乎会拉下两张图片,但 FireFox 似乎只会拉下一张)

The reason I want to know is I'm interested if it pulls down two image srcset dose it swap between them automatically as i scale the browser window?我想知道的原因是,如果它拉下两个图像 srcset 剂量它会在我缩放浏览器时自动在它们之间交换,我感兴趣 window? This is can't tell as by inspecting the element it just gives the raw html of the img element, not the actual img srcset option its using.这不能通过检查元素来判断,它只是给出img元素的原始 html,而不是它使用的实际img srcset选项。

The image has a property currentSrc, you can log it or inspect it with several tools:该图像有一个属性 currentSrc,您可以使用多种工具记录它或检查它:

  • In chrome developer tools inspect the element, then click the properties tab.在 chrome 开发者工具中检查元素,然后单击属性选项卡。
  • In Firefox developer tools inspect the element, right click and select DOM from the context menu.在 Firefox 开发人员工具中检查元素,右键单击并从上下文菜单中选择 DOM。

You will see an entry for currentSrc: with the actual image source.您将看到 currentSrc: 的条目,其中包含实际图像源。

在此处输入图片说明

I had problems with this today and I found that you can monitor the variable:我今天遇到了这个问题,我发现你可以监控变量:

  1. Show the console drawer (You can do it pressing ESC too)显示控制台抽屉(你也可以按 ESC 来完成)

在此处输入图片说明

  1. Create live expression (I created 2, the currentSrc of the selected element and the innerWidth)创建实时表达式(我创建了2个,被选元素的currentSrc和innerWidth)

在此处输入图片说明

The live expression watches the current srcset of the img tag selected.实时表达式监视所选 img 标签的当前 srcset。 It works with the img inside the picture tag too.它也适用于图片标签内的 img。

OK, go to inspect element in chrome.好的,去检查 chrome 中的元素。 Click on the network tab, then refresh the page.单击网络选项卡,然后刷新页面。

It will show you the images that are being loaded, the time they take and the size.它将显示正在加载的图像、它们花费的时间和大小。

Came upon this with the same question.带着同样的问题想到了这个。 My simple solution was to just right click image and 'Open Image on New Tab / Window'.我的简单解决方案是右键单击图像并“在新选项卡/窗口上打开图像”。

Fast and easy solution and you can see what image is loaded at different break points.快速简便的解决方案,您可以查看在不同断点处加载的图像。

I was wondering that too.我也想知道。 I think I figured that out without using any developer tools.我想我在不使用任何开发人员工具的情况下就明白了这一点。

To check I simply did a right-click and save-as to see what file name was filled in (and if it matched my high-res image or the low-res one.)要检查,我只需右键单击并另存为以查看填写的文件名(以及它是否与我的高分辨率图像或低分辨率图像匹配。)

The answer to part of your question was No, not all browsers automatically swap between different srcset image sources when your resize the browser.部分问题的答案是否定的,当您调整浏览器大小时,并非所有浏览器都会在不同的 srcset 图像源之间自动交换。 I checked in August, 2018 with several different Windows desktop browsers.我在 2018 年 8 月使用几种不同的 Windows 桌面浏览器进行了检查。 Some responded differently, but most did not swap the image unless you also hit refresh after.有些人的反应不同,但大多数人不会交换图像,除非您在之后也点击刷新。

I did not directly investigate which images were actually being downloaded or if more than one were at a time.我没有直接调查实际下载了哪些图像,或者一次下载了多个图像。 I only tested which image was actually displayed and if that image changed on browser resize.我只测试了实际显示的图像以及该图像是否在浏览器调整大小时发生了变化。 I made assumptions based on the results, which may or may not be 100% true, but seemed like a quick and dirty good start.我根据结果做出了假设,这可能是也可能不是 100% 正确,但似乎是一个快速而肮脏的良好开端。

This isn't a quick solution, but it gives a definitive answer.这不是一个快速的解决方案,但它给出了明确的答案。

  1. Upload an image - I'm using wordPress add_image_size() to create a bunch of images.上传图片 - 我正在使用 wordPress add_image_size() 创建一堆图片。
  2. Open the uploads file, find the images, open them in PhotoShop or Gimp, and write the name of the file in each image and resave it (same file name, same location).打开上传的文件,找到图片,在PhotoShop或Gimp中打开它们,在每张图片中写下文件名并重新保存(相同的文件名,相同的位置)。
  3. Now you can play around with resizing your window and tweaking the srcset and sizes until you're satisfied.现在您可以尝试调整 window 的大小并调整 srcset 和大小,直到您满意为止。 I was happy to see that as the window changed size, the image was changed (no refresh needed) often without a visible flicker.我很高兴地看到,随着 window 尺寸的改变,图像也发生了变化(无需刷新),而且经常没有可见的闪烁。

暂无
暂无

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

相关问题 是否可以重新计算在调整浏览器窗口大小时使用的`srcset`图像? - Is it possible to recalculate the `srcset` image used if browser window is resized? 有没有一种方法可以在浏览器中显示图像而不在开发人员工具中预览图像? - Is there a way to display an image in the browser without having a preview of the image in the developer tools? 浏览器从 srcset 为视口选择错误的图像 - Browser choose wrong image from srcset for the viewport 当浏览器以一半的图像大小加载时,IMG SRCSET加载图像 - Img srcset loading images when browser at half image size 使用 srcset 时浏览器应该下载多张图片吗? - Should the browser download multiple images when using srcset? 是否可以使用任何浏览器的开发人员工具来扩展整个dom树? - Is there a way to expand the entire dom tree using any browser's developer tools? 浏览器未在开发人员工具中显示缩小的CSS的CSS源 - Browser not showing css sources from minified css in developer tools 如何在浏览器开发人员工具中了解损坏源的来源? - How to know origin of broken source in Browser Developer Tools? 浏览器开发人员工具中的Discovery JavaScript执行路径和文件 - Discovery JavaScript execution path and files in Browser Developer Tools 什么是:: before或:: after表达式,为什么它显示在浏览器开发人员工具中? - What is the ::before or ::after expression, and why is it shown in the browser developer tools?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM