2

I understand concepts of HTML compression, but let's say you have a massive table with huge repeats of table related tags and their respective classes.

Instead of every table element having their own class (and each element having a class= property), you run couple of short scripts at the end using jQuery and selectors to add the correct classes. Would that improve the page load significantly? What metrics would measure whether this type of optimization is worthwhile?

3

Yes, it often makes sense to construct the DOM with JavaScript on the frontend rather than serving it directly as HTML. For example it is common for a server API to send data as JSON which is then parsed and displayed with JavaScript. Beyond jQuery there are a variety of libraries and frameworks for doing this sort of thing: Handlebars, Vue, etc.

As far as metrics, rendering the DOM with JavaScript is typically lighter on the server but heavier on the browser and vice versa for rending with the server. But the exact metrics depend on the server and browser. There are a variety of speed tests for doing your own comparisons. For example you could compare times with Lighthouse in Chrome. If you do some googling, you can find various articles (eg. here) further discussing speed and related issues like SEO.

| improve this answer | |
  • 1
    To add, the device being served might not have the processing power of a server and often such things should be rendered server side rather than on the device but, as stated, these things can and should be measured and tested. – Rob Dec 24 '19 at 13:25

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.