DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Google AMP Aftermath: Replacement Image Results

Google AMP Aftermath: Replacement Image Results

About a month ago, I implemented an ActionFilter to modify images in a post to match Google's AMP requirements. Today, I give you an update of the results! But before I give you the results, I want to explain how much work went into this particular project...

Jonathan Danylko user avatar by
Jonathan Danylko
·
Apr. 21, 16 · Web Dev Zone · Analysis
Like (3)
Save
Tweet
4.69K Views

Join the DZone community and get the full member experience.

Join For Free

laptop displaying google search engine

about a month ago, i implemented an actionfilter to modify images in a post to match google's amp requirements .

today, i give you an update of the results! but before i give you the results, i want to explain how much work went into this particular project.

the amount of work put into this was merely a new controller and a new actionfilter called useampimage .

at first, i tried displaymodes , but that didn't seem to work because of the caching.

so, i decided to create a brand new controller called amp to output a plain post as per google's request.

once implemented, i just had to wait to find out whether everything was functional or not.

the results

after a month, i decided to check the statistics on google's webmaster tools...err...i mean, google's search console .

with the minimal amount of effort (a controller and an actionfilter), i was able to update my site to use amp pages.

finally, here are the results of my efforts.

graph from google's search console describing the results of implementing google amp pages

excellent! i was extremely happy with this.

however, what about those 20 pages? call me a perfectionist, but i had to figure out what was up with those remaining pages.

fixing an issue

after looking over the 20 pages that weren't working, i noticed something weird with each post.

every time i requested one of the 20 pages, i noticed i didn't get any html back. it was a blank page.

what the...?

i went back through the code and everything seemed alright, but then i noticed each post didn't have an image anywhere in the post. it was just text with hyperlinks.

it seems i needed to add one line to the code. here is the updated updateampimages method.

private string updateampimages(string response){    // use htmlagilitypack (install-package htmlagilitypack)    var doc = gethtmldocument(response);    var imagelist = doc.documentnode.descendants("img");
     const string ampimage = "amp-img";
    if (!imagelist.any()) return response;
    htmlnode.elementsflags.add("amp-img", htmlelementflag.closed);    foreach (var imgtag in imagelist)    {        var original = imgtag.outerhtml;        var replacement = imgtag.clone();        replacement.name = ampimage;        response = response.replace(original, replacement.outerhtml);    }
    return response;
}

notice after the string constant? if we don't have any images in the post, just return the response.

conclusion

i uploaded the change and so far, it seems to be working.

i will probably give it another two weeks before i examine what google detects in my code, but this is far from over.

i guarantee i will have more errors to fix, but it seems this is a case of fixing one set of errors will result in a ripple across and fix the next set of errors.

stay tuned.

have you implemented google amp pages yet? are you having any luck? please share your comments.

Google (verb)

Published at DZone with permission of Jonathan Danylko, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Debugging Deadlocks and Race Conditions
  • How to Hash, Salt, and Verify Passwords in NodeJS, Python, Golang, and Java
  • Application Scalability — How To Do Efficient Scaling
  • Querying Kafka Topics Using Presto

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo