0

I have a page of photo thumbnails on my site. On the page, a large number of links are grouped together consecutively, and the links take up at least 1/2 the HTML code size.

Here's an example:

<div>
<a href="1">1</a>
<a href="2">2</a>
<a href="3">3</a>
<a href="4">4</a>
....
<a href="50">50</a>
</div>

What I'm thinking to significantly reduce code size from about 20 bytes per link (which equals 10KB for pages with 500 links) to maybe a few dozen bytes total is to generate the links via javascript like this:

<div ID=\"links\"></div>
<script>
var div=document.getElementById("links");
for (n=1;n<=50;n++){
    var anchor=document.createElement("A");
    anchor.href=n;
    anchor.innerHTML=n;
    div.appendChild(anchor);
}
</script>

I did read at https://support.google.com/webmasters/answer/2721306 that automatically generated content is a bad idea but at the same time I'm trying to make users download fewer bytes.

My question is would search engines understand that I'm trying to produce actual static links with this code? and would all search engines consider this code legal, or would any search engine flag me? And we need to look at the buggy aspects of google because I don't want a robot to flag my account for generating static links via javascript.

The only reasons I'm looking into this is because I could cut my code size by at least 1/2 and also because I'm providing a static (non javascript-based link) on the same page that will allow guests to see content the javascript generated anchor tags link to.

  • Google has been able to read DOM events for EONS. Use Firebug or similar and view the DOM... what you see in there is basically what Google can see too. – Simon Hayter Nov 26 '15 at 18:56
  • "would all search engines" - Whilst Google would probably be able to read this content (as Simon suggests), most other search engine bots still don't process JavaScript. The Google article regarding "automatically generated content" would seem to be about something unrelated? – MrWhite Nov 26 '15 at 19:17
  • Now if google is the only search engine to be able to process javascript, then I wonder what other engines would think of this change. would they believe it would provide a negative experience? I want to maintain my client base and at the same time optimize my site. – Mike Nov 26 '15 at 19:20
2

Automatically generated content is not the same as programmatically generated markup. The Google guideline you linked to does not relate to the change you're proposing.

Whilst I'm all for improving site speed, you should really focus things that will actually make a difference. You've said in other questions that your HTML pages are served gzipped - shaving a few kilobytes of HTML markup from a gzipped page is a miniscule amount that will have little effect on the time it takes the page to download. Also, if your markup is really that repetitive, you might find that the HTML-only version is smaller gzipped than the javascript version, since it will compress better.

Since you seem concerned about how search engines view your site, making it harder for them to index your content (by dynamically generating it client side) would seem like a bad approach. (And if you have a non-js version of this markup on the page anyway, why do you need both?)

Post a webpagetest.org report for the page you're trying to improve (perhaps in chat), and I'm sure we can suggest some better things for you to look at. There are good tools for measuring and monitoring site speed, so you don't need to guess at what might help.

  • webpagetest.org/result/151126_NS_151Y ... The only other improvements that can be made are whatever the advertisers can improve in their ads because the ads take up over 2/3 of the entire page loading time. This particular page has over 200 mostly repetitive links. – Mike Nov 26 '15 at 19:29
  • To be fair there isn't a lot you can improve there. But your time to first byte is 72ms, and then the content download for your HTML page is 33ms. So it takes your server twice as long to generate the page as it takes the browser to download it. I'd probably focus my attention on improving that TTFB figure (so application code or server-side optimisations). – Tim Fountain Nov 27 '15 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.