![]() ![]() Caching Method 2: ETagĬomparing versions with the modification time generally works, but could lead to problems. Caching saves the day (err… the bandwidth). Sending the short “Not Modified” message is a lot faster than needing to download the file again, especially for giant javascript or image files. Browser: Great! I’ll show the user the cached version.Server: Hey, you’re in luck! It was not modified since that date.Server: (Checking the modification date).Browser: Hey, give me logo.png, but only if it’s been modified since Mar 16, 2007.The next time the browser needs logo.png, it can do a special check with the server: Now the browser knows that the file it got (logo.png) was created on Mar 16 2007. A server can return a Last-modified date along with the file (let’s call it logo.png), like this: Last-modified: Fri, 04:00:25 GMTįile Contents (could be an image, HTML, CSS, Javascript.)` One fix is for the server to tell the browser what version of the file it is sending. So why bother caching if we can’t be sure if the file is good? Luckily, there’s a few ways to fix this problem. After all, the file may have changed on the server and there could be an updated version. So even though the browser has the logo, it doesn’t know whether the image can be used. The shiny new logo needs to go with the shiny new site, caches be damned. What happens when the company logo changes? becomes ? Google becomes Quadrillion? This avoids having to download the image ever again and is perfect, right? The browser saves a copy of a file (like a logo image) and uses this cached (saved) copy on each page that needs the logo. (The actual HTTP protocol may have minor differences.) Caching’s Ugly Secret: It Gets StaleĬaching seems fun and easy. Browser: That’s rad, I’m downloading it now and showing the user.Here’s a quick refresher on how a web browser gets a page from the server: Fewer downloads means a faster, happier site. The next time the user needs that resource (such as a script or logo that appears on every page), the browser doesn’t have to download it again. In the case of websites, the browser can save a copy of images, stylesheets, javascript or the entire page. You can save time by using space to store results. What is Caching?Ĭaching is a great example of the ubiquitous time-space tradeoff in programming. Time invested in site optimization is well worth it, so let’s dive in. ![]() It’s a jarring (aka bad) user experience. Users hate waiting, we get frustrated by buffering videos and pages that pop together as images slowly load. But the reason is simple: site performance is a feature.įor web sites, speed may be feature #1. I’ve been on a web tweaking kick lately: how to speed up your javascript, gzip files with your server, and know how to set up caching. ![]()
0 Comments
Leave a Reply. |