Customizing SMF > SMF Coding Discussion

Accelerated Mobile Pages (AMP)

(1/5) > >>

Today while browsing Webmaster Tools, I decided to look into AMP in more detail. I seen it before but it always thought I didn't need such a thing.

Will I decided to play around with it according to the standard and did a little buffer rewriting.

--- Code: ---function amp_rewrite_buffer($buffer) {

// Allowed with formatting, this code needs to be better.
$ctamp = array('img','video','audio','iframe');
foreach ($ctamp as $item)
$buffer = str_replace('<'.$item, '<amp-'.$item, $buffer);

$doc = new DomDocument();
$xpath = new DOMXPath($doc);

// Script is not allowed only if it is ld+json
while($node = $xpath->query('//script[@type!="application/ld+json" or not(@type)]' )->item(0))

// Not allowed elements
$remove = array('frame', 'frameset', 'object', 'param', 'applet', 'embed','form');
foreach($remove as $item)
while($node = $xpath->query('//'.$item)->item(0))

//button is allowed, no documentation on radio though.
$types = array('input','textarea','select','option');
foreach($types as $type)
while($node = $xpath->query('//input[@type="'.$type.'"]')->item(0))

// Send the doc from the dom back to the buffer
$buffer = $doc->saveHTML();

// We do this last for a reason.
$buffer = str_replace('</head>', '<script async src=""></script><style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript></head>', $buffer);

return $buffer;
--- End code ---
This doesn't render the page fully compliant and it doesn't look all that pretty without all that script and html charm that was removed.

After all, I was just thinking wouldn't it be easier just making a mobile template.  ::)

What are your ideas and opinions about AMP.

If form isn't allowed, posting isn't going to work.

Neither is quick moderation, or logging in...

Nope... It requires too much for already established software, and I don't think it has huge difference compared to responsive. Another Google boosted project.

I went ahead and implemented this a while back and looks like it does have some SEO benefits on Google on mobile. I didn't use the code I posted above and went the template route.

The page below and a screen shot of the search listing on mobile, beat Wikipedia for the search phrase.

And here is a topic view.

You're also using personalised data which will also bias places you've already been above places you haven't been so much - as shown by the 'you went here on xxx' - which sort of makes it hard to use as evidence that, objectively, it improved things.


[0] Message Index

[#] Next page

Go to full version