aWebDeveloper
aWebDeveloper

Reputation: 38352

rendering html via javascript

how good is it to load/render repeating elements in a html page via JavaScript. I know a few(5%) of ppl dont have js enabled. So is it really worth it. I can get up to 15-20% reduction in markup and in turn page size by doing so

Upvotes: 2

Views: 291

Answers (5)

Quentin
Quentin

Reputation: 943571

If you care about page size, then turn on compression on your server instead.

Repeating content compresses very well, so your 15-20% is going to be a much smaller proportion of the page weight (and the HTML is probably going to be insignificant compared to any images you have anyway).

Avoid content generation with JS if you can, it is another point of failure.

Upvotes: 1

Cyril Gupta
Cyril Gupta

Reputation: 13723

In my opinion, most of the people who have JS disabled on their browser for various reasons (official, security), won't fit the profile of a client for most websites. The reason is that almost all of us are targeting the regular Joe who is uses Gmail with Ajax, and experiences the web in multimedia.

I would recommend using JS if it is making your product work better.

Upvotes: 0

Ben Torell
Ben Torell

Reputation: 2093

If you're not loading the HTML data asynchronously, you could use a server-side language (like PHP) to print the repeating HTML before the page is served to the browser. If that's not an option, then you'll need to either stick with the Javascript you already have or suck it up and type it out manually.

In this day and age, it's mostly acceptable to tell users that they have to have Javascript enabled to view your website.

Upvotes: 0

Harry Joy
Harry Joy

Reputation: 59660

IMO you should use js to generate dynamic html. And if user has disabled js then you can give him a warning that "You should enable JavaScript for my website to work best."

Upvotes: 0

Archan Mishra
Archan Mishra

Reputation: 905

I dont think that 15% reduction in size warrants a run of JS because the JS engines are really different across all platforms and the extra JS code which works on all Browsers will be of same length. Moreover the time taken by Browser to compile JS and the make DOM tree and then Add it to the Document and render it will make ur page slow.

Upvotes: 1

Related Questions