开发者

Best Practice: Jquery Ajax versus no dependence on javascript

I have a dashboard type of page that contains a bunch of sections, each providing different data. Getting all the data and then sending the page is slow. From a perceived performance standpoint, I'm thinking the best way to do this is to load the page with each of these sections containing nothing, then use jquery ajax to asynchronously get the various pieces of data. However, it has b开发者_StackOverflow社区een drilled into my head that I should not depend on javascript to be enabled. Is there any way to detect if javascript is enabled in the requesting browser before sending back the page? Or, maybe a better question is what is the best way to go about this?


Probably 99% of users have JavaScript enabled now. Unless you care a whole lot about the people running browsers that are 10 years old, or about the absurdly paranoid users, I would just use JavaScript. Your case is what AJAX was designed for.


What I think you want to do is build your page using unobtrusive javascript.

What this will let you do is build a perfectly functional page for non-javascript enabled browsers, which can be enhanced for (the vast majority) who have javascript.

To stop a single request being a heavy payload for non-javascript browsers, make the user have to click a link to get each piece of data.


If your dashboard is part of a backend system, then I would make JavaScript a requirement and use AJAX to update the page. The visual responsiveness will be greatly enhanced, and as the backend of a site (or app) it has a more limited and controllable audience.

Be sure to have some sort of warning that appears if JS is disabled.

Even on front end sites its debatable, but many programmers still opt to plan for no JS support which would a little hard to implement in this scenario.


You should probably do this in two steps:

  1. Code your page as if javascript never existed. Use semantic markup and a good css structure (that will be easier to tamper with once you do start playing around), but don't use any javascript whatsovever.

  2. When everything works, start adding javascript beautifications. Animations, asynchronous calls (that might require further implementation on the server side) and other stuff, but nothing that you need to change the html from step 1 for. If you need the html to be different, change it with javascript - that way you won't have destroyed anything in your fallback app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜