单个大缓存CSS vs针对页面的小CSS代码段 [英] Single big cache-able CSS vs page-specific small CSS snippets

查看:301
本文介绍了单个大缓存CSS vs针对页面的小CSS代码段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我的CSS文件看起来像这样:

Right now my CSS files look like this:

然后我有一个php片段,如下所示:

Then I have a php snippet that looks like this:

<?php $Compress->folder(Configuration::get('Public').'/style/',
                        '.css',
                        Configuration::get('Public').'/style.css'); ?>

这会将存储在目录 public_html / style / (如图所示),并在名为style.css的目录 / public_html / 中创建一个文件。

This minimizes all the css files stored in the directory public_html/style/ (shown in the picture) and creates a file in the directory /public_html/ called style.css. It is run only when needed, although in development, always.

然后我只需要包含一个大文件:< link rel =stylesheet href =http://newfutureuniversity.org/style.csstype =text / cssmedia =screen>

Then I just include the big file: <link rel="stylesheet" href="http://newfutureuniversity.org/style.css" type="text/css" media="screen" >.

我专注于php开发,现在我实际上开始开发网站的设计,并希望优化它。据我了解,用户下载的文件越少,它们越小,就越好(因此我的连接和最小化类)。但是这引发了其他问题,当有很少的特定页面的CSS文件。为什么我的主页面必须加载表单CSS文件?还是形成主页一个?据我所知,有3个主要选项:

I was focused on php development, and now I'm actually starting to develop the design of the site and would like to optimize it. As far as I understand it, the less files the user has to download and the smaller they are, the better (thus my join-and-minimize class). However this raises other question, when there are few page-specific CSS files. Why would my main page have to load the form CSS file? Or the form the main page one? As far as I know, there are 3 main options:

当用户第一次访问网站时,他会下载整个最小化的css文件。第一次它会慢,但每隔一次访问它会快得多。也更容易配置。

The first time the user visites the site, he downloads the whole minimized css file. First time it will be slow, but every other visit it will be much faster. Also it's much easier to configure.

每次访问都有中等速度;第一个稍慢,然后下一个更快,但仍然不是最好的。第一次用户下载2个文件,共同的一个缓存下次访问。

Every visit has a medium speed; the first one slightly slower and then the next ones a bit faster but still not the best. First time user downloads 2 files, and the common one is cached for next visit.

每个页面的CSS是所需的CSS加上特定的页面,因此不能存储在缓存中。

The CSS of each page is the needed CSS plus the page specific, so it cannot be stored in cache. Faster than first time of 2. but slower later on.

我只是猜测它是多少页用户访问量和页面特定代码量。如果一般用户访问1或2页,您需要使用第2个或甚至第3个选项。但是,如果用户访问您的网站的20或30页,那么您需要第一个选项。

I am JUST guessing that it comes down to how many pages the user visits and the amount of page-specific code. If the average user visits 1 or 2 pages, you'd want the 2nd or even 3rd option. However, if the user visits 20 or 30 pages of your site, then you want the 1st option.

因此,这种方法将更好的服务器负载和用户延迟和为什么?

So, which method would be better for both the server load and the user latency and why? The page I'm working on needs to be small, since mobile access and remote location access is expected.

推荐答案

我个人认为,下载一个,大的CSS文件比导致多个HTTP请求,特别是如果你的网页通过浏览器只允许两个同时HTTP请求每个域浏览。此外,样式表将缓存以供后续请求使用。

Personally, downloading one, large CSS file is preferable to incurring multiple HTTP requests, especially if your web page is being viewed via a browser that only allows two simultaneous HTTP requests per domain. Plus, the style sheet would be cached for subsequent requests.

这篇关于单个大缓存CSS vs针对页面的小CSS代码段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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