# 在 Discourse 中，所有 js 和 css 文件都是单独呈现的。为什么不将它们合并成一两个文件来提供呢？

**URL:** <https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793>\
**Category:** Development\
**Tags:** css\
**Created:** [2024年五月5日 12:16 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793 "2024-05-05T12:16:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)\
**Post date:** [2024年五月5日 12:16 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/1 "2024-05-05T12:16:45Z")

</div>

在 Discourse 中，所有 js 和 css 文件都是单独呈现的。多年来，我一直认为将这些文件合并、优化和呈现是更好的做法。如果我遗漏了什么重要的事情，请警告我，但遗憾的是，初始加载速度非常慢，减少这些文件的数量是否有益？

例如，如果只有 1-2 个 css 文件而不是 30 个 css 文件，是否能进一步加快进程？

想象一下，如果您的网站在地址栏输入并按 Enter 键后，在 1-2 秒内打开。嗯，那将是太棒了。

[https://www.webpagetest.org/result/240505\_BiDc8X\_6JJ/](https://www.webpagetest.org/result/240505_BiDc8X_6JJ/)

![video](https://global.discourse-cdn.com/meta/original/4X/a/b/1/ab1147fec62230a11b026eb24d337cf8a5f783b1.gif)

**我同意，它非常实用，打开后速度非常快，我们对此非常满意……让我们再改进一点，让它成为最好的中的最好的** 🙂

---

<div class="post-metadata">

**Author:** ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)\
**Post date:** [2024年五月5日 12:23 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/2 "2024-05-05T12:23:42Z")

</div>

这看起来很合理。

> [@Javascript Aggregation](https://meta.discourse.org/t/javascript-aggregation/154009/2?u=kuaza):
>
> Discourse sites are all hosted on HTTP/2 the practice of bundling is a best practice on HTTP/1.1 and can in fact be a bad practice in many cases on HTTP/2

---

<div class="post-metadata">

**Author:** ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)\
**Post date:** [2024年五月5日 14:50 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/3 "2024-05-05T14:50:57Z")

</div>

对我来说，这里的现实是2秒。那些实验室测试是另一个世界。

---

<div class="post-metadata">

**Author:** ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)\
**Post date:** [2024年五月5日 15:13 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/4 "2024-05-05T15:13:09Z")

</div>

但是，仍有至少 5-6 秒的等待时间。当我在外面测试时，等待时间可能真的很长。

---

<div class="post-metadata">

**Author:** ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)\
**Post date:** [2024年五月5日 15:17 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/5 "2024-05-05T15:17:07Z")

</div>

连接缓慢？

---

<div class="post-metadata">

**Author:** ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)\
**Post date:** [2024年五月5日 15:18 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/6 "2024-05-05T15:18:29Z")

</div>

我将在有机会时进行测试。

---

<div class="post-metadata">

**Author:** ![Ed\_S](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ed_s/32/134015_2.png) [@Ed\_S](https://meta.discourse.org/u/Ed_S)\
**Post date:** [2024年五月5日 20:45 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/7 "2024-05-05T20:45:29Z")

</div>

> [@Jagster](#):
>
> 那些实验室测试是另一个世界

我认为其中一部分是因为他们进行了冷启动并且必须加载所有资源。大多数时候，论坛用户会在他们的浏览器中缓存这些资源。

我确实怀疑加载时间可能有所改进，也许其中一些实验室测试的技巧值得跟进。

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2024年五月6日 07:52 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/8 "2024-05-06T07:52:23Z")

</div>

> [@kuaza](#):
>
> 例如，如果只有1或2个CSS文件而不是30个CSS文件，是否可以进一步加快进程？

这里需要证据，打包（bundling）对HTTP 1.1网站有很大好处，但对2.0网站则不然。

> **[HTTP/2 technology demo](http://www.http2demo.io/)**

我当然希望东西能更快，但当JavaScript中的`eval`是瓶颈时，调整打包就不是正确的方法。

---

<div class="post-metadata">

**Author:** ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)\
**Post date:** [2024年五月7日 21:35 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/9 "2024-05-07T21:35:03Z")

</div>

我认为这不仅仅局限于HTTP标准。有些网站2-3秒就能打开。Discourse的10秒等待屏幕有点令人烦恼。土耳其有句谚语：“每个美女都有瑕疵”。我希望Discourse能随着时间的推移纠正这个缺陷。

---

<div class="post-metadata">

**Author:** ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)\
**Post date:** [2024年五月9日 17:51 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/10 "2024-05-09T17:51:44Z")

</div>

同样——它来自论坛服务器、用户的连接和用户的设备。

我不知道团队如何能解决美国、芬兰或土耳其所有地区之间的差异，或者让拥挤的 4G 网络提供 3M 速度更快。或者，如果用户使用的是内存不足且充满搞笑猫咪照片的入门级中国手机。

当然。如果 Discourse 被构建成“普通”网站，第一次可能会更快。但那样的话，每次页面加载都会同样慢甚至更慢。

说实话，如果 Discourse 对你来说很慢，那确实很糟糕。但对我来说，在芬兰，我的 iPhone SE 在家里的 Wi-Fi 上，信号来自 4G，营销速度是 200M，等待时间大约是 2 秒。

---

<div class="post-metadata">

**Author:** ![kuaza](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuaza/32/264151_2.png) [@kuaza](https://meta.discourse.org/u/kuaza)\
**Post date:** [2024年五月9日 18:20 UTC](https://meta.discourse.org/t/in-discourse-all-js-and-css-files-are-presented-separately-why-dont-we-combine-them-into-one-or-two-files-and-present-them/306793/11 "2024-05-09T18:20:00Z")

</div>

今天我想到了一件事。这个应用程序功能一直很快。我会告诉你如何向每个用户介绍和安装它。这样，它既像一个应用程序，又能给人留下快速的印象。我喜欢 Discourse。暂时我无意离开它。我会想尽一切办法充分利用它。
