I have recently discovered that none of my one client's details pages have ever been indexed. This is because of JavaScript, client-side rendering.
If the search engines can't see the links to the details pages, they will never get indexed.
Here is how I rectified the situation:
In my app.get('/example') route (in Node.js with Express) I had the following
const express = require('express'),
app = express(),
db = require('./db'); // database controller
app.get('/example',function(req,res){
var queryName = 'getExample';
db.rows(queryName, function(err, rows){
var data = {
filename: 'example',
details:rows
};
res.render('index',data);
});
});
I simply added to the code the logic that used to be on the client-side (with slight modifications):
app.get('/example',function(req,res){
var queryName = 'getexample';
db.rows(queryName, function(err, rows){
var data = {
filename: 'example',
details:rows
};
data.list = '';
for(var i = 0; i < rows.length; i++){
if(rows[i].item_id){
data.list += '<div style="display:inline-block;width:220px; padding:5px; margin:10px; border:1px solid #DDD; height: 400px;vertical-align:top;position: relative;">' +
'<a class="detail" style="color: #777" id="id_' + rows[i].item_id + '" href="/details/'+rows[i].id+'">' +
'<img style="height: 200px; width: auto" src="/uploads/' + rows[i].hash + '/' + rows[i].top + '">' +
'<div>' + rows[i].title.replace('-/-','-') + '</div>'+
'<div style="width: 200px;font-weight: bold; text-align: right; position: absolute; bottom: 10px; right: 10px;">';
if(rows[i].length){
data.list += '<div style="text-align: right;">' + rows[i].length + 'mm x ' + rows[i].width + 'mm x ' + rows[i].depth + 'mm</div>';
}
if(parseFloat(rows[i].weight)){
data.list += '<div style="text-align: right;" data-id="' + rows[i].item_id + '"><b>' + rows[i].weight.toFixed(2) + ' ct</b></div>';
} else {
data.list += '<div style="text-align: right;" data-id="' + rows[i].item_id + '"></div>';
}
data.list += '<div style="text-align: right;""><b>' + rows[i].item_id + '</b></div>' +
'</div>'+
'</a></div>';
}
}
});
});
res.render('index',data);
And on the client-side, with EJS:
<div id="list">
<%- list; %>
</div>
Now I have all links visible to the search engines. Hopefully I will get them indexed soon! 🤞
Note: You are making a payment to Web Renegade
Leave a comment