使用 AJAX 加载页面内容是个好主意吗?

发布于 2024-10-29 17:49:47 字数 60 浏览 1 评论 0原文

基本上,对于网站的index.html页面,而不是使用php来加载网页的中间部分(页眉和页脚之间的内容)?

Basically, lets say for the index.html page of a website, instead of using php to load the middle section( content between header and footer ) of the webpage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦境 2024-11-05 17:49:47

您可能会遇到这样的情况。例如,如果您的“页面”确实是一个相当重量级的客户端 Web 应用程序,那么这也许是正确的选择。但总的来说,这是一个糟糕的主意。

生成一个已经充满了您的内容的页面有什么害处?您可以避免兼容性问题、SEO 问题,加载速度快,并且可以减少对服务器的 HTTP 请求。仅仅因为“融入这种理念的优秀 JS 框架”的存在并不意味着它是适合您的应用程序的正确方法。

每个站点都不同,但默认答案应该肯定不是。如果条件合适的话,可以。此决定应基于什么对您的用户最有利。

You may come across a situation that this is good for. For instance, if your "page" is really a rather heavy-weight client-side web application, then perhaps this is the right choice. Generally though, this is a terrible idea.

What harm do you have in generating a page already filled with your content? You avoid compatibility issues, SEO issues, it loads quickly, and that's one less HTTP request to your server. Just because "good JS frameworks that incorporate this philosophy" exists doesn't mean it is the right method for your application.

Each site is different, but the default answer should be certainly not. If the conditions are right, then yes. Base this decision on what is best for your users.

浮萍、无处依 2024-11-05 17:49:47

是的。许多框架正在朝这个方向发展,大多数消费网站(Facebook、Twitter)在加载主页后加载大部分内容。

如果您的用户拥有支持 JS 的浏览器,AJAX 负载可以通过为可能更改的内容提供更快的响应时间和更动态的界面来改善用户体验。如果做得正确,它实际上会通过前端携带数据组织和表示方法来提高应用程序的可维护性。

如果您想深入研究,有一些优秀的 JS 框架可以将这种理念融入到您的设计中,SproutcoreBackbone 都值得研究。

编辑

我现在正在构建网络应用程序,所以我以这种倾向阅读问题。正如人们所指出的,如果您只是构建小册子网页,那么您将看不到 AJAX 内容加载的真正好处,并且会损害您的 SEO。

Yes. Many frameworks are moving in this direction, and most consumer sites (Facebook, Twitter) load most of the content after the main page is loaded.

Provided your users have JS enabled browsers, the AJAX load improves user experience by providing a faster response time and a more dynamic interface for the content which is likely to change. If done correctly, it will actually improve the maintainability of your application by carrying data organization and presentation methodologies through your front-end.

If you want to dive all the way in there are good JS frameworks that incorporate this philosophy into your design, Sproutcore and Backbone are both worth looking into.

Edit

I'm building web applications now, so I read questions with that slant. If, as people have pointed out, you're just building brochureware webpages then you won't see a real benefit from AJAX content loads and will hurt your SEO.

水中月 2024-11-05 17:49:47

如果您假设每个访问者都有支持 AJAX 的浏览器(我指的是打开 JS 等),那么这几乎是正确的。我不确定(源代码看起来像),但这似乎是 Facebook 加载中间部分的方式。

当然你也必须使用 PHP,我希望你知道。

If you assume that each of your visitors has AJAX-enabled browser (by which I mean JS turned on, etc.), then that would be pretty much correct. I'm not sure (source code looks like), but this seems to be the way Facebook loads it's middle section.

Of course you will have to use PHP either, I hope you know.

绝對不後悔。 2024-11-05 17:49:47

如果搜索引擎优化是项目的一个关注点,那么答案是否定的=)

搜索引擎通常只获取每个页面的源代码。

If Search Engine Optimization is a concern for the project the answer is NO =)

Search engines generally only fetch the source code for each page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文