提高网站性能

发布于 2024-09-08 03:25:59 字数 160 浏览 6 评论 0 原文

我有一个相当大的网站(asp.net web),我大量使用了 JavaScript(jquery、自定义 javascipt 等)以及主题和 CSS。现在我的系统中有大量的js和css文件,我正在考虑缩小和粉碎js和css以提高性能。因此,请建议我使用合适的工具和技术,并建议我在这些场景中应用的最佳实践。

I have a pretty big web site (asp.net web) and I have used JavaScript intensively (jquery,custom javascipt, etc) and also The theme and CSS. Right now I have a huge amount of js and css files in my system and I am thinking about minifying and smashing the js and css to improve the performance. So, please advice me the suitable tools and technologies to be used and please suggest me the best practices to be applied in these scenario.

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

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

发布评论

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

评论(3

鹿港小镇 2024-09-15 03:25:59

您可以尝试采取一些措施来提高性能。

我列出了我们组织中用来提高 Web 应用程序性能的技术。除了 GZIP 之外,其他两个可能不会对 JS 和 CSS 文件产生直接影响,但会为您节省其他方面宝贵的加载时间,使您的网站速度更快。

当零售属性设置为“True”时,我们总是看到速度和性能的巨大提高 - 在此模式下禁用所有形式的调试,这使得网站响应更快。

显然,您只希望在实时服务器上进行此设置。

There are a couple of things you could try to improve performance.

I've listed the techniques we have used at our organisation to improve the performance of our web applications. With the exception of GZIP the other two probably won't have a direct effect on the JS and CSS files but will save you valuable loading time in other areas making your web site much faster.

We always see huge increases in speed and performance when the retail attribute is set to 'True' - all forms of debugging are disabled in this mode which makes the site more responsive.

Obviously you only want this setting on your live server.

农村范ル 2024-09-15 03:25:59

如果您使用 jQuery,则应该已经使用缩小版本 在您的生产现场。

对于您自己的 Javascript,可以使用 Douglas Crockford 的原始 minifier,或者您也可以使用 Microsoft Ajax Minifier,您可以将其添加为 MSBuild 任务 - 有一个概述 此处

这个问题的答案中引用了许多 CSS 缩小器。

If you're using jQuery, you should already be using the minified version on your production site.

For your own Javascript, there's Douglas Crockford's original minifier, or you could use the Microsoft Ajax Minifier, which you can add as an MSBuild task - there's an overview here.

There's a number of CSS minifiers referenced in the answers to this SO question.

死开点丶别碍眼 2024-09-15 03:25:59

最佳实践固然很好,但至少在性能方面,问题更多的是关于正确的实践。唯一了解的方法是:

  • 测量
  • 尝试
  • 再次测量
  • 比较/对比

这几乎总是与优化软件的权衡。您必须考虑更改如何影响可读性、可扩展性、安全性、部署复杂性,以及可能还有许多我没有想到的其他特性

话虽如此,您正在寻找的实践几乎都在这里

为了阐明我的观点,请考虑使用 CDN 规则。对于像 jquery 这样的通用工具来说,这似乎是一个显而易见的选择。您可以使用 MSFTGoogle 为此。您具有并行下载的潜在优势(取决于客户端浏览器)以及已经位于客户端缓存中的可能性(来自他们可能访问过的其他站点)。另外,他们的服务可能比您更接近用户。

但需要考虑的权衡是,它会消耗一些带宽,因此,如果您正在构建位于 Intranet 中的东西,请不要这样做。您还引入了外部来源失败的可能性。您可以通过添加更多代码。

也许最重要的是,使用 CDN 与第一条规则(减少 HTTP 请求)形成直接对比。如果您可以组合并最小化所有 js 并在本地更有效地加载它,那么您应该这样做。你怎么知道?
您必须:

  • 测量
  • 尝试
  • 再次测量
  • 比较/对比

玩得开心!

Best practices are great but, at least in the case of performance, the question is more about the right practice. The only way to know is to:

  • Measure
  • Try
  • Measure Again
  • Compare/Contrast

It is almost always a trade-off with optimizing software. You have to consider how a change effects readability, scalability, security, deployment complexity, and probably a lot of other ity's I am not thinking of.

Having said all that the practices you are looking for are pretty much here.

To make my point though consider the rule Use a CDN. This seems like an obvious choice for something universal like jquery. You can use both MSFT and Google for this. You have the potential advantage of parallel download (depending up on the client browser) and the added possibility of already being in the client cache (from other site they may have visited). Plus they are likely serving it closer to the user than you are.

But the trade off to consider is that it is going to eat some bandwidth so if you are building something that is sitting in the Intranet, don't do this. You also introduce the possibility of failure from an external source. You can work around that by adding more code.

Perhaps most importantly though is that using a CDN is in direct contrast to the first rule, reduce HTTP requests. If you can combine and minimize all your js and load it more efficiently locally then you should do so. How do you know?
You have to:

  • Measure
  • Try
  • Measure Again
  • Compare/Contrast

Have fun!

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