5

I assume everyone has used the "interesting tags" feature. You select a tag and the questions with selected tag are highlighted by addition of the CSS class tagged-interesting.

The highlighting is done by JavaScript after the DOM is loaded (because it was not working when JS was disabled). So, until the DOM is completely loaded, there is no highlighting. Since I am on a slow connection, the highlighting takes place only after a long time (around 5-6 secs).

Why was JavaScript was used for this, when it could have been done server-side by simply adding the class? That wouldn't have caused much overhead to the server.

I want to know the rationale behind it (I am sure it exists) because, as recently I learned during my internship, JavaScript should strictly be used for user interaction purposes (like up-voting).

Am I thinking along the wrong lines?

1
  • one could argue that this is a strictly user interaction type functionality. Feb 28, 2010 at 18:48

2 Answers 2

8

SO makes use of page caching, by using using JavaScript to alter the page content for each user they can serve the same HTML and CSS back to the browser, and then just use JS to alter the highlighted content based off the users tags.

3
  • can't the main page be cached and when it is served, the classes are added accordingly?
    – nvl
    Feb 28, 2010 at 19:00
  • @Joseph : could you please elaborate? :) thanks
    – nvl
    Feb 28, 2010 at 19:33
  • @nvl I suggest you read the blog a little, and also listen to the podcasts (especially the earlier ones). You'll get some interesting insights and behind-the-scene details about Stack Overflow. blog.stackoverflow.com
    – balpha StaffMod
    Feb 28, 2010 at 19:38
0

My guess is that it simplifies caching html. No need to store both variants in cache.

1
  • Poor excuse - they all render per-user data at some point to know which questions to feature. They could instead render a per-user css file and adjust the html so each tag also has it's own css class that matches the tag name. That would work in at least the technical sense. I think the problem might be if google frowns on per-user css, because it could be used to hide data in a way that's hard for them to detect. Mar 1, 2010 at 2:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .