Skip to content

Instantly share code, notes, and snippets.

@samthecodingman
Last active July 28, 2024 06:06
Show Gist options
  • Save samthecodingman/7a96a2a1c55d33f0c5ec1bc9107f0e9a to your computer and use it in GitHub Desktop.
Save samthecodingman/7a96a2a1c55d33f0c5ec1bc9107f0e9a to your computer and use it in GitHub Desktop.
Reload the current page using Google's Web Cache [Javascript Bookmarklet] [CC-BY License]
javascript:(window.location.href.indexOf("webcache.googleusercontent.com")>-1)?alert("Error:%20You%20are%20on%20the%20cached%20version."):window.location.assign("http://webcache.googleusercontent.com/search?q=cache:"+encodeURIComponent(window.location.href.replace(/(^\w+:|^)\/\//,'')));
@samthecodingman
Copy link
Author

Google Web Cache Bookmarklet

How to use

To use this bookmarklet, add it as a Bookmark to your favourites bar of your browser under the 'URL' or 'Location' field. When clicked, the Javascript function will run and reload the page from Google's Web Cache. If a page is not cached by Google (usually because of a robots.txt file), you will get a 404 error.

Why use a bookmarklet?

Well, in comparison to a full plugin, a bookmarklet consists of a small amount of text that just performs the function you need. It may not be as pretty as a plugin, but it doesn't require updating, doesn't have version incompatibilities and most importantly won't actually read any of the page's contents. So there is zero snooping/logging/tracking risk.

How it works

On the surface...
The bookmarklet is actually quite primitive and simplistic, consisting of some simple error checking using the ternary operator:

isThisTheGoogleCache() ? isSoShowErrorMsg() : notSoLoadGoogleCache()

A more in depth look...
Using that analogy, isThisTheGoogleCache() checks if the current page is from the Google Web Cache by searching for the substring "webcache.googleusercontent.com" in the page URL.

window.location.href.indexOf("webcache.googleusercontent.com")>-1

When that check is true, an error is thrown in the form of a warning dialog.

alert("Error:%20You%20are%20on%20the%20cached%20version.")

If the page isn't from the Web Cache, the URL scheme (usually http://, https:// or '//') is removed from the current URL, encoded and then passed to the Google Web Cache.

window.location.assign("http://webcache.googleusercontent.com/search?q=cache:"+encodeURIComponent(window.location.href.replace(/(^\w+:|^)\/\//,'')));

Props to cachedview.me for pointing out that the URL scheme should be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment