Home How to prevent images beeing cached in chrome with ASP.net MVC and jquery ajax?
Reply: 0

How to prevent images beeing cached in chrome with ASP.net MVC and jquery ajax?

user2283
1#
user2283 Published in July 21, 2018, 9:52 am

Im really confusing. I do have a ASP.net MVC application and on my view I perform an jquery ajax call like this:

 $.ajax({
            type: "Get",
            cache: false,
            dataType: "json",
            url: "/Place1/Refresh_PLC_Data",
            success: function (response) {
                UpdatePage(response);
            }

My controller action looks like this:

    public JsonResult Refresh_PLC_Data()
    {
      // Return
        var retObject = serializer.Serialize(ViewModel);
        return Json(retObject, JsonRequestBehavior.AllowGet);
    }

Inside the json result I have an array with (virtual directory) picture pathes.

On my view I show (slideshow) all pictures inside the array.

The pathes inside the array are:

"../../QWData/NI/Folie1.JPG"
"../../QWData/NI/Folie2.JPG"
"../../QWData/NI/Folie3.JPG"

and so on.

My slideshow is working fine. But if I change some of the pictures inside the original folder, the browser is still showing me the "old" one.

I tried the following thinks to prevent caching the images by the browser:

Chrome Registry change:

from: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -- "%1"
to: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -disable-application-cache –media-cache-size=1 –disk-cache-size=1 — "%1"

I added the following to my controller action:

[OutputCache(Duration = 0, NoStore = true)]
public JsonResult Refresh_PLC_Data()
{
    Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
    Response.AppendHeader("Expires", "0"); // Proxies.    

    // Return
    var retObject = serializer.Serialize(ViewModel);
    return Json(retObject, JsonRequestBehavior.AllowGet);
}

I also started Chrome in Incognito-Mode.

But the browser is sometimes showing me old pictures...

What else could I do. The best for me would be to disable the cache completely. Is it possible? (I can only disable it by F12 - developer mode).

Thank you.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.321481 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO