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
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.
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.
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."
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.
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.
精彩评论