The picture is preloaded, and there are multiple loads.

there are too many active images and I want to preload them, but I find that they are loaded multiple times and are not read from the cache.

<body>
    <img src="./img/arrow.png" id="slogn">
    <div class="loading" id="loading" style="display: none;">
        <div class="slogan"></div>
    </div>
<script>
var loadImg = new Image();
loadImg.src = "img/slogn.png";
loadImg.onload = function () {
    document.getElementById("slogn").src = "img/slogn.png"
    setTimeout(function () {
        document.getElementById("loading").style.display = "block"
    },5000)
}
</script>
</body>

css:


.slogan{
  background: url("../img/slogn.png") no-repeat center;
}

clipboard.png

I see that many people use new Image to preload pictures, but here they don"t read data from the cache. How do you preload pictures?

Apr.05,2021

the header of your picture file is not set to be cached. Set cache-control and etag


there is usually a loading page before the active page. Load the picture resources and then jump to the active page

.

the plug-in demo https://github.com/chenyinkai.

can only be tested.

try this npm I preload-all-S

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e52379-4410e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e52379-4410e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?