Last post Sep 01, 2020 09:41 AM by Rena Ni
Aug 31, 2020 04:44 PM|ShatterStar|LINK
I currently have my default Index() action in my HomeController that returns images in a json format with the actual physical url of the image on the server, the problem with this is that it hits the server everytime that the Index() action is called. What
alternative method can I use to cache the images?
Aug 31, 2020 05:56 PM|PatriceSc|LINK
It shouldn't change anything. If this is really an url (rather than a data url, not sure what you call a "physical url") you still end up with an http request that could be cached (and is perhaps already ?). How do you later load load the image? You are
not using Ajax but rather assign that to an img.src ?
You can configure caching for static files as shown at https://stackoverflow.com/questions/57254048/how-to-cache-static-files-in-asp-net-core
You could use the approach shown at https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/image-tag-helper?view=aspnetcore-3.1 to
reload the static file if it changed (you would include the hash or version in your urls).
As often I would start by using F12 Network in the browser to first make sure about what is the current behavior before moving forward.
Sep 01, 2020 09:41 AM|Rena Ni|LINK
the problem with this is that it hits the server everytime that the Index() action is called. What alternative method can I use to cache the images?
For the index action is always called,just create a button when you click it then it could hit the index action.
For cache images,not sure what is your image used to do,please share more details.