Preload images using jquery

后端 未结 3 839
感情败类
感情败类 2021-02-10 08:38

In my web page some images are taking a lot of time to load in IE.So I used this for preloading images in my page.But still the problem persists.Any suggestions?



        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-10 09:05

    Images sprites can speed things up tremendously (but make sure you compress them using something like ImageOptim). Next, host all your images on a CDN somewhere (I suggest Amazon S3/CloudFront). And lastly, preload all your images using something like below, and try and call this as early as possible. Hopefully this helps!

    function loadImages(){
        var images = [
            'http://cdn.yourdomain.com/img/image1.png',
            'http://cdn.yourdomain.com/img/image2.jpg',
            'http://cdn.yourdomain.com/img/image3.jpg',
            'http://cdn.yourdomain.com/img/image4.jpg'
        ];
        $(images).each(function() {
            var image = $('').attr('src', this);
        });
    } 
    

提交回复
热议问题