Using image.complete to find if image is cached on chrome?

I’ve rewritten your code in plain JavaScript, to make it more independent on jQuery. The core functionality hasn’t changed. Fiddle: http://jsfiddle.net/EmjQG/2/ function cached(url){ var test = document.createElement(“img”); test.src = url; return test.complete || test.width+test.height > 0; } var base_url = “http://www.google.com/images/srpr/nav_logo80.png” alert(“Expected: true or false\n” + cached(base_url) + “\n\nExpected: false (cache-busting enabled)\n” + cached(base_url + … 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

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