我第一次遇到这个问题还是在DHTML盛行的时代. 我们对浏览器无所不用其极, 加上各种动画菜单、3D标签(我们现在已经学会不再使用这些了), 但总有人告诉我们javascript不可用.
谁禁用了javascript
第一个要问的问题是这些javascript不可用的环境在哪里. 下面是一些可能的答案:
安全系统比如noscript或者公司代理过滤掉了javascript;
功能手机比如旧式黑莓(我还记得将旧式黑莓换到Opera Mini以获得总算还过得去的上网体验);
在移动应用环境中, 图片和脚本有时候会被拆分处理;
在流量有限或者接入很慢的区域中;
人们因为个人原因禁用了javascript;
讨厌广告弹出等强势广告的人.
就像你所看到的那样, javascript被禁用的原因多种多样, 有被动的, 也有主动的. 所以不能说只有乱用网络的人才会遭遇这样的问题.
为什么javascript会被禁用
像上面所列举的那样, javascript被禁用的原因多种多样. 如果它是被有意禁用的, 那么我猜主要原因无非以下三点, 即安全考虑、广告疲劳以及慢速连接.
安全考虑在情理之中. 几乎每一个在客户端的攻击都是使用的javascript(大多数情形下都是利用了插件的漏洞). Java当然是当前最大的安全漏洞, 但是通过javascript同样会对存在漏洞的网站或者不经保护或者过时的浏览器以及操作系统造成安全威胁.
慢速连接是个很有意思的原因. 非常讽刺的是, 我们使用javascript是为了加速客户端体验. 最初使用js的一个例子就是在客户端对表单进行验证从而避免服务器端不必要的工作周期.
如果你现在正处于一个很差的连接中(比如一个无线连接或者很差的3G连接), 你想要使用Google Reader或者Gmail, 你只能得到一个不完整的页面, 这时候只有使用低版本的才能更好工作.
为了两方都好
基于环境以及连接给用户最好的体验是非常好的. 这也是渐进增强(progressive enhancement)所研究的问题. 这也并非是很高深的东西, 它很简单, 并且是处于完全的实用主义.
使用事件授权这样的技术是非常简单的. 你可以通过点击父元素的handlers来写你自己的HTML, 使用innerHTML或者其他一些更新更快的技术.
为什么是这样一个问题
坦白说, 我也不太清楚. 或许是因为我太过时了, 或许是因为我已经一次有一次对浏览器和网络连接失望了, 或许是因为我只想更安全一些. 我只是不明白为什么人们只想要js的解决方案呢, 而实际上, js只是用来提供一些增强功能的.
费解的应用边缘案例
人们时常怀有疑问的是"应用需要javascript". 如果我们足够坦诚, 我们就会发现, 这样的应用实际上是很少的. 如果一定要说出一些, 我只能想到的是浏览器中的photoshop或者其他的一些编辑器(比如视频、浏览器中的IDE)才需要依赖于javascript. 其他都可以通过重新加载和服务器端的一些部件解决.
让我们直面这样一个事实——在Node.js的时代, 服务器端也可以用javascript来写. Dav Glass of Yahoo两年前显示如果一个工具库编写成余环境独立的, 那么你就可以同时在客户端和服务器端复用这些工具.
"应用需要javascript"的真正原因似乎是其他原因, 而非技术上的.
"应用需要javascript"的真正原因
正如禁用javascript可以有很多原因, 应用需要javascript也有很多原因.
You only know JavaScript and think that people should upgrade their browsers. This is understandable, but this view is very narrow-minded and can easily fail.
The team you work with to build the application has no server-side skills. You want to be able to build the application at a low cost. This may work, but it may double the development time and money. Plan for such development in advance.
You want to write the application as soon as possible, and you Know that you will rewrite this application in the future. This is very common, especially if you can be successful because of it. May God bless you, and don't let people know that you will be around for a long time.
Your application will be in Run in a pure js environment. This of course means that you don’t have to complete your application without using js. A good example is Air applications. But you have to ensure that this environment will not cause problems in the future.
Your The app does require js to run. If that's the case, don't serve it to users who don't have js. Explain to people why and how (try to avoid telling people they need to enable js because they may not be able to do it and be more disappointed) ), and use js to redirect to your application.
Summary
In short, the problem of javascript dependency is not just for technical reasons. It raises questions about old technical practices and has a big impact on maintainability.
It can be said that if we can ask "why do we need js" instead of asking "why do people don't have js", the discussion on this issue will be more fruitful. If our technology can adapt well to different needs, go to There is no point in blaming people for not keeping up with the development of the Internet.
It also makes no sense to show the user that they can solve the problem by enabling or disabling widgets in the browser. When a normal user is stuck in your app, it is not a good idea to tell the user what is going on. .
Perhaps all these issues will no longer be a problem once node becomes mature and popular. I would be happy to see that.
Original link: That "javascript not available" case