ajax 比表单提交中重新加载页面更快吗?

发布于 2024-11-05 15:43:54 字数 80 浏览 0 评论 0原文

我有一个一般性问题:通过 Ajax 加载数据是否比加载整个页面来捕获数据更快,无论页面大小如何(外部元素如图像、css 文件、js 文件...)?

i have a general question : is loading data via Ajax totally faster than loading the whole page to grap data regardless of page size(external elements like images,css file,js file ...) ?

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

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

发布评论

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

评论(4

埋葬我深情 2024-11-12 15:43:54

正如已经提到的,使用 AJAX 方法可以让您避免重新加载大部分页面,包括脚本、样式和图像,即使 AJAX 请求和响应可能不会更快。

同样重要的是要注意,流畅、微妙的动画现代 AJAX 界面通常比用户感觉的要快得多。重新加载页面似乎具有重置大脑中某些内容的效果,而仅以平滑的方式更新页面的相关部分就可以使所有内容“流动”在一起。

我知道,非常主观。任何优秀的设计师都可能有更好的方式来解释它。

As already mentioned, using AJAX methods, lets you avoid reloading most of the page, including the scripts, styles and images even though the AJAX request and response may not be any faster.

It is also important to note that a slick, subtley animated modern AJAX interface often feels much faster than it is to the user. Reloading the page, seems to have the effect of resetting something in the brain, whereas just updating the relevant parts of a page in a smooth way makes everything just 'flow' together.

Very subjective, I know. Any good designer probably has a better way of explaining it.

生生漫 2024-11-12 15:43:54

@Spender是正确的,但主要原因是您没有重新抓取页面的图像、css、js和任何其他资产。请求本身可能会更快,也可能不会更快,但最终的渲染会更快。

@Spender is correct, but the main reason is that you do not re-grab the images, css, js and any other asset of the page. The request itself may or may not be faster but the final rendering is.

離殇 2024-11-12 15:43:54

是的。 (虽然你没有具体说明哪种更快)

Yes. (Although you fail to specify what kind of faster)

南烟 2024-11-12 15:43:54

是的,有两个主要原因。

在实践中,AJAX 总是“更快”。不是请求本身;大致相同。不同之处在于,它只传输必要的最少内容(如果写得好的话),不会重新启动整个页面(从 CSS 解析、渲染、构建整个 DOM 等),并且您可以在页面运行时在后台执行此操作。仍然可见,因此您可以做其他事情,例如制作动画,甚至提前更新,预测明显的结果。对用户体验的祝福。

但还有更多。

最重要的是事物的顺序。当您加载页面时,标记首先到达,然后是脚本和样式,通常图像最后到达。只有经过所有这些处理之后,您的页面才会具有真实的外观。现在,当您使用 AJAX 更改(甚至整个)标记时,一切都会立即就位,然后当您的浏览器意识到后果时,其中一些会发生更改。换句话说:当一切都完成时,页面重新加载在视觉上就会“完成”; AJAX 更改会立即显示。这就是它的真正力量。您已经拥有所有图像、所有列表、所有内容,并且您仅加载更改的内容

所以:是的,速度要快得多。

Yes, for two main reasons.

In practice, AJAX is always "faster". Not the request itself; that's approximately the same. The difference is that it transfers only the necessary minimum (if well written), doesn't start the whole page over (from CSS parsing, rendering, building the whole DOM, etc), and you do it in the background while the page is still visible so you can do other things, like animating stuff or even updating in advance, predicting the obvious results. A blessing for user experience.

But there's more.

The most important is the order of things. When you load a page, markup arrives first, then scripts and styles, and usually images come last. Only after all this processing will your page have the real look. Now when you change (even the whole) markup with AJAX, things are immediately in place, then a few of them change as your browser realizes the consequences. In other words: a page reload becomes visually "done" when everything is done; AJAX changes show up immediately. This is the real power of it. You already have all images, all lists, all everything, and you load only what's changed.

So: yes, it's a lot faster.

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