How does Google handle the indexing of content when History API is involved?
Asked Answered
K

1

6

I say I have a section of a page like this (rough HTML to give an idea):

www.mydomain.com/contact-us

<div class="regional-offices">

<div class="south-west">
  <a href="#south-west">South West</a>
  <div class="south-west-content">South west office address</div>
</div>

<div class="north-east">
  <a href="#north-east">North East</a>
  <div class="north-east-content">North east office address</div>
</div>
...
...

Currently, these are a set of accordions that expand to show the content when the link is clicked. What I would like to do is treat them as individual URLs so that they can be seperately indexed by Google, as of course at the moment they are just part of a single page.

I have been researching the History API and can see how I would do this as far as creating unique URLs for each section, but where my understanding falls down is how Google or other search engines will handle these links if the required info is already part of the page and not stored at its own seperate URL.

For instance, the first step would be to change the <a> tag to be something like:

<a href="/contact-us/north-east">North East</a>

We can then use JS to preventDefault() going directly to the URL, and instead provide the user with an expanded accordion, bring the page scroll down to the accordion and a unique URL using the History API. This is all well and good if we visit the URL directly, or click any of the links.

But the problem is that as far as I know, the Google crawler will try to follow the link and be faced with a 404 because there's no Javascript preventing access to the resource in the URL. And nor do I want there to be.

Or is it the case that I will need a unique location holding the contents of the accordion, which is indexable, and also pulled in with AJAX when a collapsed accordion is interacted with?

Apologies if I haven't made anything clear.

Karalee answered 11/2, 2016 at 14:8 Comment(0)
L
0

I had to deal with the same thing. What I did was to make a rewrite rule so that the link that google follow is actually posted to the page that handle the the request. to display the data. Angular might save you a lot of trouble to dealing with accordions.

Leid answered 22/2, 2016 at 0:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.