你想要做的是什么叫progressive enhancement。
此图片是从我发布的链接:
概括地说,这是什么说明的是,你的网站应该没有CSS或JavaScript达到基本的最小功能。换句话说,如果你有一些网站,你应该看起来像这样:
<!DOCTYPE html>
<html>
<head>
<title>Basic HTML</title>
</head>
<body>
<h1>Introduction to semantic HTML</h1>
<p>You use H tags for headings, search engines like that.
Paragraph tags for paragraphs</p>
<a href="http://example.com/">Hyperlinks make sense</a>
<div>
<p>Divs can be used to create seperate areas for content</p>
</div>
</body>
</html>
这是什么样的?
在现代的网络浏览器:
在命令行的浏览器有很多人使用:
CSS和JavaScript应该加强这基本功能,不需要它。
当我转到您的网站,并要求http://example.com/Foo
我应该看到
<!DOCTYPE html>
<html>
<head>
<title>Foo page</title>
<script>/*Whatever script that does your ajaxy stuff*/</script>
</head>
<body>
<h1>Foo page</h1>
<p>Foo content</p>
<a href="http://example.com/bar">Click here to goto bar.</a>
<div>
<p>Divs can be used to create seperate areas for content</p>
</div>
</body>
</html>
我不应该看到的是:
<!DOCTYPE html>
<html>
<head>
<title>Foo page</title>
<script>/*Whatever script that does your ajaxy stuff*/</script>
<script>/*Script to Load in the main content for the body*/</script>
</head>
<body>
<noscript>
<p>Sorry, for some reason I decided you need
javascript and a modern desktop browser to see
the basic line of text you wanted.</p>
</noscript>
</body>
</html>
因此,而不是让你的网页基础上的URL加载内容在浏览器中的页面,您应该从服务器端提供页面,这样当您请求/ foo时,您将获得所有foo HTML。然后,当它加载时,通过使特定的导航链接加载主体内容来编写将通过逐步增强页面的JavaScript。这样当JS被禁用时,它可以工作,并且当JS被启用时,你的内容加载速度更快。
从可用性的角度来看最后一点。
如果你要做到这一点ajaxy东西,请请确保您要确保捕获所有HTTP错误代码和做正确的事一样提醒使用者错误加载页面,并显示加载图形。 Ajaxy网站尝试和加载内容时,我有一个缓慢的网络,并没有告诉我有关加载内容或发生的错误,让我挂出去干,让我一个非常生气的用户,只是离开你的网站,永远不会回来。
我在想同一 – ArcDare 2012-02-15 14:10:48
页面原本很慢,因为我不得不等待一些远程第三方系统的请求。我希望页面加载时无需等待这些结果,然后在返回时添加结果。 – 2012-02-15 14:16:26
好的,我明白了。因此,该页面正在等待可能需要一段时间的资源。数据从第三方系统改变的频率如何?像每个页面加载一样,第三方系统是加载唯一信息还是数据相同?我建议,因为你的一些用户可能没有启用js,那么明智的解决方案是在服务器端使用缓存。像memcache之类的东西可以产生很大的差异,如果新数据可能来自第三方来源,则可以经常刷新数据。 – user1207047 2012-02-15 14:23:22