Forums >> Programming >> Web Programming

Jump to:




bvstone

Responsive Design, Dynamic Content Swapping/Single Page Applications (SPAs), SEO and GoogleBots -- Part 2

Posted:

Responsive Design, Dynamic Content Swapping/Single Page Applications (SPAs), SEO and GoogleBots -- Part 2

After a few weeks with our new responsive/mobile site not getting indexed (despite putting all information on the main page) we decided to try something else.

Previously most of our clickable "links" which trigger the website to update the content in a Single Page Application (SPA) method were list (li) items.

<li class="menuSelect" data-id="quickkey">Get a Temporary License key (Quick Key)</li>

So, we decided to update them to hyperlinks as follows:

<li><a href="/ssi/quickkey.html" class="menuSelect" data-id="quickkey">Get a Temporary License key (Quick Key)</a></li>

There's one problem with this... now the browser will take the user to a small Server Side Include (SSI) page which contains only the main content and not the "rest" of the site.

This was easily solved with a little JavaScript:

$('body').on('click', '.menuSelect', function (event) {
  event.preventDefault();
  var name = $(event.target).attr('data-id');
  var text = $(event.target).text();

  if (! $(this).hasClass("noMenuUpdate")) {
    $("#menuNav").append("<span class='addedMenuNavBarItem'>" + 
      ">> </span><a class='addedMenuNavBarItem' data-id='" + 
      name + "'>" + text + "</a>");
  }

  loadBodyContent('/ssi/' + name + '.html');

});	

All we did was add the preventDefault() method to our click code and that stopped the navigation from happening, at least for real visitors to our site.  Our hope is that Google (and other) crawlers will follow the link and index the page and it's contents.

But that brings up another problem... when a user clicks on the link from search result list from Google, Bing, etc. they'll be shown the plain SSI page, not the real page.  (See our update to this issue here!) Instead of redirecting automatically (and possibly defeating the reason for this in the first place) we added the following JavaScript to each page (using an SSI) that had an anchor with an href:

<script>
  if (window.location != 'http://m.bvstools.com/') {
    document.write("<a href='http://m.bvstools.com'>Click Here</a> to view the full site.<br><br><br><br>");
  }
 </script>

What this does is give the user a link to click on to return to the "full" site, but should, in theory, allow the site and the important contents to be indexed.

As an example, click the following link:

http://m.bvstools.com/cgi-bin/softdesc?software=MAILTOOL

You are taken to a page that displays only the "content".  That content is meant to be placed into a container (or <div>) on the main page.  But, the JavaScript that is included in the page sees that the window location isn't the home page, so it then provides a link to the user to click to return to the proper main page and allows the SPA website to function properly.

I'm sure there are other solutions (possibly more elegant as well) but we're going to see how this helps, or doesn't help, the indexing with Google and Bing.  

So far, just a couple hours after resubmitting the site as well as a sitemap to Google, we are starting to see our results show up... so, we may be on to something here.


Last edited 07/29/2015 at 09:26:28



Latest Posts:

BVSTools is Now Running V7R4M0 BVSTools is Now Running V7R4M0
Posted by September 28, 2019
BVSTools >> BVSTools Announcements
GreenTools for G Suite (G4G) Now Includes Send Mail Functionality (G4GSMAIL Addon) GreenTools for G Suite (G4G) Now Includes Send Mail Functionality (G4GSMAIL Addon)
Posted by August 27, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools For G Suite (G4G) v12.00 Released With Base OAuth 2.0 Functionality GreenTools For G Suite (G4G) v12.00 Released With Base OAuth 2.0 Functionality
Posted by July 28, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
BVSTools Small Price Increase in 2020 BVSTools Small Price Increase in 2020
Posted by July 26, 2019
BVSTools >> BVSTools Announcements
GreenTools for Vertex Cloud (VTXCLOUD) Now Available GreenTools for Vertex Cloud (VTXCLOUD) Now Available
Posted by July 22, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Vertex Cloud (VTXCLOUD) Specific Announcements
GreenTools for Google Apps (G4G) - Drive Addon Successfully Verified by Google GreenTools for Google Apps (G4G) - Drive Addon Successfully Verified by Google
Posted by July 22, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Why I Cancelled my DynDNS Service and How I Replaced It with an IBM i Application Why I Cancelled my DynDNS Service and How I Replaced It with an IBM i Application
Posted by July 17, 2019
IBM Power Systems >> (QGPL) IBM i
Green Tools for G Suite (G4G) Product Updates (Licensing, Functionality, Base Product) Green Tools for G Suite (G4G) Product Updates (Licensing, Functionality, Base Product)
Posted by July 13, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Reading JSON Data from Standard Input With YAJL and RPG Reading JSON Data from Standard Input With YAJL and RPG
Posted by July 12, 2019
Programming >> Proof of Concept (POC)
MAILTOOL Updated to Allow Use of IBM Global Security Kit (GSKIT) for SSL/TLS Communications MAILTOOL Updated to Allow Use of IBM Global Security Kit (GSKIT) for SSL/TLS Communications
Posted by June 19, 2019
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
GETURI v10.00 Released Supporting IBM Global Security Kit (GSKIT) and Server Name Indication (SNI) GETURI v10.00 Released Supporting IBM Global Security Kit (GSKIT) and Server Name Indication (SNI)
Posted by June 11, 2019
BVSTools >> BVSTools Announcements >> Get URI (GETURI) Specific Announcements
BVSTools Now Offers Vertex Cloud Interface BVSTools Now Offers Vertex Cloud Interface
Posted by April 15, 2019
BVSTools >> BVSTools Announcements
Token Has an Invalid Signature Error for Office 365 Email Token Has an Invalid Signature Error for Office 365 Email
Posted by March 22, 2019
BVSTools >> BVSTools Software Discussion >> GreenTools for Microsoft Apps (G4MS) Specific Discussion
Resending Emails that have Errored Out with Updated Router or Authentication Information Resending Emails that have Errored Out with Updated Router or Authentication Information
Posted by March 1, 2019
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
BVSTools Offers Toolset to Work With HubSpot OAuth 2.0 APIs On Your IBM i BVSTools Offers Toolset to Work With HubSpot OAuth 2.0 APIs On Your IBM i
Posted by January 27, 2019
BVSTools >> BVSTools Announcements
bvstone

RE: Responsive Design, Dynamic Content Swapping/Single Page Applications (SPAs), SEO and GoogleBots -- Part 2

Posted:

RE: Responsive Design, Dynamic Content Swapping/Single Page Applications (SPAs), SEO and GoogleBots -- Part 2

Well, it's official.  This new method helped the indexing of our sites tremendously!

So, it appears that (for now) the web page technology is a little ahead of the crawling technology.  Crawlers like hyperlinks, not Single Page Applications (SPAs) and dynamic content swapping.


Last edited 07/23/2015 at 08:05:57



bvstone

RE: Responsive Design, Dynamic Content Swapping/Single Page Applications (SPAs), SEO and GoogleBots -- Part 2

Posted:

RE: Responsive Design, Dynamic Content Swapping/Single Page Applications (SPAs), SEO and GoogleBots -- Part 2

We've now updated the application even more so instead of just viewing a plain text version of a web page with a link to the home page, we now redirect to the main page and load the appropriate content.

This was done by updating the redirect.html Server Side Include (SSI) to the following:

<script>
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

if (window.location != 'http://m.bvstools.com/') {
	// document.write("<a href='http://m.bvstools.com'>Click Here</a> to view the full site.<br><br><br><br>");
	var software = getParameterByName('software');
	var path = window.location.pathname;
	console.log(path);
	
	if (software != '') {
		createCookie('navigateToSoftwarePage',software,1);
		window.location = 'http://m.bvstools.com';
	} else if (path != "") {
		createCookie('navigateToPage', path, 1);
		window.location = 'http://m.bvstools.com';
	}	else {
		document.write("<a href='http://m.bvstools.com'>Click Here</a> to view the full site.<br><br><br><br>");
	} 
}

</script>

So what we are doing here is first parsing the Query String value to see if there is a software name.  If there is, we create a cookie (using a couple cookie functions) named navigateToSoftwarePage and give it the value of the software.

If there is no software name, we instead create a cookie named navigateToPage which will include the pathname property of the current window location.

Once these cookies are set we then change the window's location to the main page.

That's when we will check for cookie values and load the appropriate page:

$(window).load(function() {
	// When the page has loaded
	$(".hideMe").hide();
	$("body").fadeIn(100);
	var navigateToSoftwarePage = readCookie("navigateToSoftwarePage");
	var navigateToPage = readCookie("navigateToPage");
	
	if (navigateToSoftwarePage != null) {
		loadBodyContent('/e-rpg/softdesc?software=' + navigateToSoftwarePage);
		eraseCookie("navigateToSoftwarePage");
	}

	if (navigateToPage != null) {
		loadBodyContent(navigateToPage);
		eraseCookie("navigateToPage");
	}
});

Once our page loads we look for either of the "navigateTo..." cookies and if they exist we call our loadBodyContent() function to load the appropriate information into our web page and then remove the cookie.

See, we knew there was a better way than just displaying an ugly unformatted page... we just needed the time to dig into it.  

To see how this works now, just go to Google or Bing and use the search "site:m.bvstools.com".  This will load the pages that are indexed by the search engines.


Last edited 07/29/2015 at 09:25:16




Reply




Copyright 1983-2019 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).