简体   繁体   English

媒体查询中移动横幅的加载时间

[英]Loading time with mobile banner in media query

I have normal banner when loading my page on a computer.在计算机上加载我的页面时,我有正常的横幅。 However, I'd like to have smaller version (so it loads faster) on mobile (media query).但是,我希望在移动设备(媒体查询)上有更小的版本(因此加载速度更快)。 My question: How does it load?我的问题:它是如何加载的? Is there any benefit when changing the banner in mobile or page loads all the files either way so it's just a waste of resources?在移动设备中更改横幅或页面加载所有文件时是否有任何好处,所以这只是浪费资源? If this doesn't improve loading time, is there any other way to do it?如果这不能改善加载时间,还有其他方法吗?

.banner1 .banner-img{
    background-image:url(../Images/banner1.jpg);
    background-repeat:no-repeat;
    background-size:cover;
    background-position:center;
}
@media screen and (max-width:768px){
    .banner1 .banner-img{
        background-image:url(../Images/banner2.jpg);
    }
}

From here https://css-tricks.com/the-complete-guide-to-lazy-loading-images/ :从这里https://css-tricks.com/the-complete-guide-to-lazy-loading-images/

If the CSS rule specifying the background image does not apply to an element in the document, then the browser does not load the background image.如果指定背景图像的 CSS 规则不适用于文档中的元素,则浏览器不会加载背景图像。 If the CSS rule is applicable to an element in the current document, then the browser loads the image.如果 CSS 规则适用于当前文档中的元素,则浏览器会加载图像。

So your css should work and should improve loading times.因此,您的 css 应该可以工作并且应该可以缩短加载时间。 You can check it using your browser's devtools.您可以使用浏览器的开发工具检查它。 The 'network' tab shows what requests the browser has made, so you can use this to check if it is loading one image or both. “网络”选项卡显示了浏览器发出的请求,因此您可以使用它来检查它是否正在加载一个图像或两者。

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

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