我应该将我的javascript合并为一个,将css文件合并为一个以提高性能吗? [英] Should I combine my javascripts in one and css files in one for performance?

查看:74
本文介绍了我应该将我的javascript合并为一个,将css文件合并为一个以提高性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

YSlow报告建议

我在特定页面上有很多javascript文件,这些文件应合并为一个. 我在特定页面上有很多CSS文件,这些文件应合并为一个.

I have many javascript files on a particular page and these should be merged in one. I have many css files on a particular page and these should be merged in one.

第一季度.任何机构都可以详细说明如何将它们合并成一个整体吗?

Q1. Could any body elaborate on this how would it be fast to merge them in one?

第二季度.如果我有条件地需要不同版本的css/javascript(由于浏览器类型或版本),我是否应该缩小并单独使用该特定文件?但这将违反将所有文件放在一个文件中的规则.如果有人通过某种方式做到这一点,请在这里分享.

Q2. In cases where I need conditionally different version of css/javascript (because of browser type or version) should I minify and use that particular file separately? but that will break the rule of putting all files in a single one. If any body has done it in a way could you please share it here.

推荐答案

每个文件请求都涉及到服务器的往返行程.您请求的文件越多,往返次数越多,页面加载速度也越慢.将尽可能多的文件合并到一个文件中可以减少请求数量,从而缩短页面加载时间.

Each request for a file involves a round-trip to the server. The more individual files you request, the more round-trips and the slower the page load. Combining as many files in to one as possible reduces the number of requests, and therefore improves page load times.

这是一个很好的经验法则,但是不要太挂了.如果您出于不同的目的需要加载不同的版本,请继续执行此操作,前提是不要将代码和CSS分成太多小片段

This is a good rule-of-thumb, but don't get too hung up on it. If you need to load different version for different purposes, go ahead and do so, provided you don't split your code and CSS into too many small fragments

构成太多"的是特定于站点和系统的.尝试一些组合,找到适合您的方法.每个系统都不一样.

What constitutes 'too many' is site and system specific. Try some combinations and find what works for you. Every system is different.

这篇关于我应该将我的javascript合并为一个,将css文件合并为一个以提高性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆