Images in server are loading very slowly RRS feed

  • Question

  • User739135361 posted


    In my application, I am trying to create user profile. These profiles also have images. Users are loading hd images which is causing to load very slowly.  I am checking for the file extention of the images and loading them. But is their a way to compress hd images if a user uploads without loosing much clarity?

    What are all the other options I need to consider? Server capability ? Hosting? or fine tune the application?



    Tuesday, July 7, 2020 6:14 AM

All replies

  • User753101303 posted


    See for example: https://stackoverflow.com/questions/1922040/how-to-resize-an-image-c-sharp

    Never tried yet but ASP.NET Core should be similar if using https://www.nuget.org/packages/System.Drawing.Common

    Maybe not noticeable for this usage but more likely the quality will degrade as the difference between the original and targeted size grows...

    Tuesday, July 7, 2020 7:46 AM
  • User1686398519 posted

    Hi N1ZAM,

    • Regarding the problem of slow image loading, you can refer to the suggestions given in this link.
    • I made an example on how to compress pictures when uploading, you can refer to it.


        public class test
            public int Id { get; set; }
            public string filename{ get; set; }
        public class FileModel
            public HttpPostedFileBase File { get; set; }


            public MVCTestContext db = new MVCTestContext();
            public ActionResult Index()
                return View();
            public ActionResult Index(HttpPostedFileBase file)
                string filename = "Compress-" + file.FileName;
                string path = Server.MapPath("/Images");
                if (!Directory.Exists(path))
                string targetPath = Path.Combine(path, filename);
                Stream strm = file.InputStream;
                if (ReduceImageSize(0.5, strm, targetPath))
                    var test = new test { filename = filename };
                return RedirectToAction("show"); ;
            public ActionResult show()
                return View(db.tests.ToList());
            private bool ReduceImageSize(double scaleFactor, Stream sourcePath, string targetPath)
                    using (var image = System.Drawing.Image.FromStream(sourcePath))
                        var newWidth = (int)(image.Width * scaleFactor);
                        var newHeight = (int)(image.Height * scaleFactor);
                        var thumbnailImg = new Bitmap(newWidth, newHeight);
                        var thumbGraph = Graphics.FromImage(thumbnailImg);
                        thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
                        thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
                        thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
                        thumbGraph.DrawImage(image, imageRectangle);
                        thumbnailImg.Save(targetPath, image.RawFormat);
                    return true;
                    return false;


    @model WebApplication5.Models.FileModel
    @using (Html.BeginForm("Index", "CompressImage", FormMethod.Post, new { enctype = "multipart/form-data" }))
        @Html.TextBoxFor(model => model.File, new { type = "file" })
        <button type="submit">submit</button>
    @Html.ActionLink("show", "show")


    @model IEnumerable<WebApplication5.Models.test>
    <table class="table">
        @foreach (var item in Model)
                <td><img src="@Url.Content(Path.Combine("/Images",@item.filename))" /> </td>

    Here is the result.

    Best Regards,


    Wednesday, July 8, 2020 6:15 AM
  • User932909087 posted

    Hi Nizam,

    You may need to check that you have optimized your images or not. If you believe you have optimized all your sites, include your code, etc, then you must check your server specs. If you are using shared hosting, the server might be overloaded so it impact to your site speed. 

    Thursday, July 9, 2020 7:46 AM