Javascript Ajax 优雅降级,不同页面?
我开始更加关注如何让我的 javascript 和 ajax 优雅地降级。更推荐哪个:
- 致力于将优雅降级合并到现有代码中(可能很棘手) 或者
- 为非 js 用户开发一组不同的页面。
我倾向于不同的页面集,因为我觉得它更容易,并且我可以为每种用户类型(启用 js 或禁用 js)提供最佳的结果。你同意我的观点吗?如果不同意,你为什么不同意?
我还担心黑客攻击。例如,黑客获取启用 js 的版本,然后禁用他的 js。关于这一点有什么想法吗?我对黑客攻击了解不多,但是如果我使用单独的版本,这会成为安全问题吗?
提前致谢
I'm starting to give a little more attention to making my javascript and ajax degrade gracefully. Which is more recommended:
- working on incorporating the graceful degradation into your existing code (can be tricky)
or - developing a different sets of pages for the non-js users.
I'm leaning towards the different sets of pages, because I feel it's easier and I get to deliver the best possible results for each user type (js-enabled or js-disabled). Do you agree with me, and if not, why do you disagree?
I'm also worrying about hacking attempts. For example hacker gets to the js-enabled version, then disables his js. Any thoughts on this point? I don't know much about hacking, but can this be a security concern if I go with the separate versions?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
虽然它不适用于现有网站,但通常使用渐进增强范式更有用:构建网站,使其无需特殊的附加组件即可运行,然后开始将您的精彩之处分层那。
这样您就可以确保它从头开始工作,并且每个人(包括使用屏幕阅读器的人、关闭图像或样式表的人以及不使用 JavaScript 的人)都可以访问您的网站。
然而,对于现有站点,这将取决于 ajax 提供的功能。一般来说,您应该努力在禁用 js 的情况下镜像所有 ajax 功能。如果您的 js 版本中存在安全漏洞,那么非 js 版本中也可能存在安全漏洞。 AJAX 无法访问任何无法通过普通 URL 访问的内容。
Though it doesn't work well for existing sites, often it's more useful to use the Progressive Enhancement paradigm: build the site so it works with no special add-ons, then start layering your awesomeness on top of that.
This way you can be sure it works from the ground up and everyone (including those who use screen readers, those who turn off images or stylesheets, and those who don't use javascript) can all access your site.
For an existing site, however, it will depend on what functionality the ajax is delivering. In general you should strive to mirror all the ajax functionality with js disabled. If you have security holes in your js version, than you probably will in your non-js version too. AJAX can't get to anything that can't be accessed via ordinary URL.
开发两组独立的页面,一组用于启用 JS,一组用于非 JS,显然是一项艰巨的工作,不仅在最初,而且随着应用程序的不断发展也是如此。如果这不会太困扰你,我认为这就是要走的路。我认为您对同页优雅降级有时非常棘手的看法是正确的。有时这只是因为布局:启用 JS 后,您可以简单地隐藏和显示元素,而没有 JS 时:将所有内容放在哪里?单独的页面集可以帮助保持页面结构更清晰。
关于黑客攻击:您永远、永远、永远不能依赖客户端 JavaScript 验证。所有内容都必须在服务器端进行检查(或重新检查),并且您的服务器端代码可能不会对用户输入做出任何假设。因此,我认为有人在使用应用程序时停用 JS 的情况是无关紧要的。尝试保持非 JS 和 JS 版本的预期用户输入一致,正确验证它,就可以了。
Developing two separate sets of pages, one for JS enabled and one for non-JS, is obviously a lot of work, not only initially, but also as your application keeps evolving. If that doesn't bother you too much, I think that's the way to go. I think you are right about same-page graceful degradation being very tricky sometimes. Sometimes this is just because of the layout: With JS enabled, you can simply hide and show elements, where as without JS: where to put everything? Separate sets of pages can help keep page structure cleaner.
About hacking attempts: You can never, never, never rely on client-side JavaScript validation. Everything has to be checked (or re-checked) server-side, and your server-side code may make no assumptions whatsoever on the user input. Therefore, I think the scenario of someone de-activating JS while using the application is irrelevant. Try to keep the expected user input uniform for the non-JS and the JS versions, validate it properly, and you're good.
您可能需要查看 jQuery Ajaxy。它可以让您优雅地将您的网站升级为功能齐全的 ajax 网站,而无需任何服务器端修改,因此一切仍然适用于禁用 JavaScript 的用户和搜索引擎。它还支持哈希,因此您的后退和前进按钮仍然有效。
它已在这两个网站(据我所知) http://wbhomes.com.au 和 < a href="http://www.balupton.com" rel="nofollow noreferrer">http://www.balupton.com
You'll probably want to check out jQuery Ajaxy. It lets you gracefully upgrade your website into a full featured ajax one without any server side modifications, so everything still works for javascript disabled users and search engines. It also supports hashes so your back and forward buttons still work.
It's been implemented on these two sites (which I know of) http://wbhomes.com.au and http://www.balupton.com