dimanche 6 janvier 2019

CSS backgroung image load very slow in my ASP.NET Core App

I've used a CSS class in one of my app's layout to display an image as the whole page background.

<body class="image">

I'm using a collection of images and want the image changed randomly whenever the page is loaded. I'm using the following java-script code snippet in a page that uses the above mentioned layout:

<script>
    var rand = Math.floor(Math.random() * 50) + 1;
    $("<style/>", { text: ".image {background: url(/images/covers/" + rand + ".jpg); background-repeat: no-repeat;background-position:center center;background-size: cover;"}).appendTo('body');
</script>

everything work well but images load slowly when the page is loading (about 5 or 6 seconds). I most point out which this slow loading only occurs when the app runs through IIS. When I run the app from Visual Studio, images changing with acceptable speed. And I should added that when using only one static image in CSS class to cover my page background, it is loading very fast (in both IIS and VS).

Any Idea?




Aucun commentaire:

Enregistrer un commentaire