image-caching
Saving image and then loading it in Swift (iOS)
This function will save an image in the documents folder: func saveImage(image: UIImage) -> Bool { guard let data = UIImageJPEGRepresentation(image, 1) ?? UIImagePNGRepresentation(image) else { return false } guard let directory = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) as NSURL else { return false } do { try data.write(to: directory.appendingPathComponent(“fileName.png”)!) return … Read more
How to make static content on Apache be cached by browser and not checked for freshness with every request?
Expires module in Apache solves this a2enmod expires it needs to be loaded in server config, and set up in .htaccess (or in server config). With an Expires header, the resource is only requested the first time. Before the expiration date, subsequent requests are fulfilled from browser cache. After the specified time expires and the … Read more
Is there a way to force browsers to refresh/download images?
Append a query string with an arbitrary unique number (or time, or version number, etc.): <img src=”https://stackoverflow.com/questions/1431512/image.png?80172489074″ alt=”a cool image” /> This will result in a new request, because of the different URL.
How to force a web browser NOT to cache images
Armin Ronacher has the correct idea. The problem is random strings can collide. I would use: <img src=”https://stackoverflow.com/questions/126772/picture.jpg?1222259157.415″ alt=””> Where “1222259157.415” is the current time on the server. Generate time by Javascript with performance.now() or by Python with time.time()