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:

MAILTOOL Updated to Allow G4GSMAIL as Option in Routers File MAILTOOL Updated to Allow G4GSMAIL as Option in Routers File
Posted by 3 days ago
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
BVSTools Now Offers Interface with Infor's ION APIs BVSTools Now Offers Interface with Infor's ION APIs
Posted by May 15, 2020
BVSTools >> BVSTools Announcements
More V7R4 IFS File CCSID Issues and The Fix More V7R4 IFS File CCSID Issues and The Fix
Posted by March 4, 2020
IBM Power Systems >> (QGPL) IBM i
Error Retrieving IP Address by Name Error Retrieving IP Address by Name
Posted by February 25, 2020
BVSTools >> BVSTools Software Discussion
Logging jobs that hit an outq Logging jobs that hit an outq
Posted by February 13, 2020
Programming >> CL Programming
GreenTools for Google Apps (G4G) v12.60 Released with Shared Drive Features and More... GreenTools for Google Apps (G4G) v12.60 Released with Shared Drive Features and More...
Posted by February 4, 2020
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Allowing Requests over Port 80 For SSL Validation (ie, Namecheap, etc) Allowing Requests over Port 80 For SSL Validation (ie, Namecheap, etc)
Posted by January 31, 2020
Programming >> Web Programming
GreenTools for Slack (G4SLK) v3.00 Released GreenTools for Slack (G4SLK) v3.00 Released
Posted by January 17, 2020
BVSTools >> BVSTools Announcements >> GreenTools for Slack (G4SLK) Specific Announcements
Calling a QSH Command from RPG Calling a QSH Command from RPG
Posted by December 26, 2019
Programming >> RPG Programming
SPLTOOL Print Range (PRTRNG) Function Updated to Handle Spooled Files up to 999,999,999 Pages SPLTOOL Print Range (PRTRNG) Function Updated to Handle Spooled Files up to 999,999,999 Pages
Posted by December 14, 2019
BVSTools >> BVSTools Announcements >> Spooled File Tools (SPLTOOL) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Updated to v6.00 - Now Uses Microsoft Graph APIs GreenTools for Microsoft Apps (G4MS) Updated to v6.00 - Now Uses Microsoft Graph APIs
Posted by November 24, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
V7R4 Changes CCSID of Compressed File Using PASE JAR Command - Here's The Fix V7R4 Changes CCSID of Compressed File Using PASE JAR Command - Here's The Fix
Posted by November 21, 2019
IBM Power Systems >> (QGPL) IBM i
Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens
Posted by November 11, 2019
BVSTools >> BVSTools Software Discussion >> Get URI (GETURI) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality
Posted by October 20, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
BVSTools is Now Running V7R4M0 BVSTools is Now Running V7R4M0
Posted by September 28, 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-2020 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).