To AMP, or Not To AMP, That is the Question: Whether ’tis Nobler in the Mind to Bookmarklet

“Hi. My name is Chris and I’m a web browser bookmarklet junkie.”

Accelerated Mobile Pages

I’ve been following most of the (Google) Accelerated Mobile Pages (AMP) discussion (most would say debate) through episodes of This Week in Google where Leo Laporte plays an interesting foil to Jeff Jarvis over the issue. The other day I came across a bookmark from Jeremy Keith entitled Need to Catch Up on the AMP Debate? which is a good catch up by CSS-Tricks. It got me thinking about creating a bookmarklet to strip out the canonical URL for AMP pages (the spec requires them to exist in markup) to make them easier to bookmark and share across social media. In addition to social sites wrapping their URLs with short URLs (which often die or disappear as the result of linkrot) or needing to physically exit platforms (I’m looking at you Facebook with your three extra life-sucking clicks meant to protect your walled garden) to properly bookmark canonical URLs for later consumption, I’ve run across several Google prepended URLs which I’d rather not share in lieu of the real ones.

Apparently I wasn’t the first to think of such a thing, nor am I the second. Last night I came across a bit of research and genius by Kevin Marks who referenced a bookmarklet by Alan Storm back in January for switching to an AMP’d version of a web page (in an effort to cut down on the large JavaScript and advertising payloads that come along with most modern web pages). Naturally there was also a bookmarklet to switch back to the canonical (and non-Google) URL included for those who want to share an original.

Clean and Simple URLs

Kevin then took it a step further and included a JavaScript bookmarklet that shortens URLs down to their pure essence.

As an example, his canonical bookmarklet will take something ugly like
/> and strip it down to its most basic
/> so that if you want to share it, it will remove all of the tracking cruft that comes along for the ride.

Even worse offenders like
/> suddenly become cleaner and clearer

These examples almost remind me of the days of forwarding chain letter emails where friends couldn’t be bothered to cut out the 10 pages of all the blockquoted portions of forwards or the annoying

>  > >>  >>
>  > >>  >>
>  > >>  >>

nonesense before they sent it to you… The only person who gets a pass on this anymore is Grandpa, and even he’s skating on thin ice.

Remember, friends don’t let friends share ridiculous URLs…

So in that spirit, here are the three bookmarklets that you can easily drag and drop into the bookmark bar on your browser:

🔲 To AMP

🔳 Not to AMP

✁ Base URL

The code for the three follow respectively for those who prefer to view the code prior to use, or who wish to fashion their own bookmarklets:

javascript:var url = false;var links = document.getElementsByTagName(‘link’);Object.keys(links).forEach(function(key){if(links[key].rel !== ‘amphtml’){return;};url = links[key].href;});if(!url){ alert(‘No AMP URL’); };if(url){document.location = url;};

javascript:var url = false;var links = document.getElementsByTagName(‘link’);Object.keys(links).forEach(function(key){if(links[key].rel !== ‘canonical’){return;};url = links[key].href;});if(!url){ alert(‘No Canonical URL’); };if(url){document.location = url;};

javascript:var c = document.querySelector(“link[rel=canonical]”); if(c){ history.replaceState({},document.title, c.href); }

As a bonus tip, Kevin Marks’ post briefly describes how one can use their Chrome browser on mobile to utilize these synced bookmarklets more readily.

Alternatives

Of course, if you want the AMP version of pages just for their clean appearance, then perhaps you may appreciate the Mercury Reader for Chrome. There isn’t a bookmarklet for it (yet?), but it’ll do roughly the same job, but without the mobile view sizing on desktop. And then while looking that link up, I also notice Mercury also has a one line of code AMP solution too, though I recommend you brush up on what AMP is, what it does, and do you really want it before adding it.