跳转到帖子
在手机APP中查看

一个更好的浏览方法。了解更多

OKCCN - XenForo & IPS Plugin Marketplace

主屏幕上的全屏APP,带有推送通知、徽章等。

在iOS和iPadOS上安装此APP
  1. 在Safari中轻敲分享图标
  2. 滚动菜单并轻敲添加到主屏幕
  3. 轻敲右上角的添加按钮。
在安卓上安装此APP
  1. 轻敲浏览器右上角的三个点菜单 (⋮) 。
  2. 轻敲添加到主屏幕安装APP
  3. 轻敲安装进行确认。
  • 选择语言

CSS Performance Optimization

推荐的帖子

  • 行政经理

CSS Performance Optimization


Optimizing CSS

Optimizing CSS makes your website load faster and run more smoothly; which also results in a better user experience.

Here are some tips for optimizing CSS:

1. Use Simple Selectors

Use simple selectors when possible. Complex selectors increase the parsing time.

Bad Example

body #navlist ul li a.button:hover {
  background-color: blue;
}

Better Example

.button:hover {
  background-color: blue;
}

2. Avoid Universal Selector for Styling

Avoid the universal selector (*) when not strictly necessary. The universal selector (*) affects every element and can slow down page rendering.

 Example

* {
  margin: 0;
  padding: 0;
  font-size: 16px;
}

3. Avoid Inline Styles

Avoid inline styles when not necessary. Inline styles make your HTML heavier and are harder to manage.

Bad Example

<div style="color: red; font-size: 18px;">Hello</div>
<p style="color: blue; font-size: 16px;">Test</p>


4. Avoid @import

Avoid using @import for loading external CSS, as it delays stylesheet loading.

Add external CSS with the <link> tag in the head section, so it loads before the page is rendered.

Example

<link rel="stylesheet" href="style.css">

5. Use Shorthand Properties

Use shorthand properties when possible. It saves space and is faster to parse.

Example

/* Long version */
margin-top: 10px;
margin-right: 20px;
margin-bottom: 10px;
margin-left: 20px;

/* Shorthand version */
margin: 10px 20px;

6. Cut Down Unnecessary Animations

A high number of animations and large animations require more processing power to handle, which degrades performance. So, remove unnecessary animations.


7. Use Properties that Not Cause Repaint of Animations

Animation performance relies also on what properties you are animating.

Some properties (like width, height, left, top), trigger a layout recalculation when animated, and should be avoided.

If possible, use animation properties that do not cause repaint, like transforms, opacity and filter.


8. Combine and Minify CSS

Use one CSS file when possible, and remove spaces and comments to reduce file size.

You can use tools like:

  • CSS Minifier
  • PostCSS
  • Online compressors

9. Cache Your CSS

Make sure your CSS file is cached by the browser by giving it a long expiration time in your server settings. This reduces how often users need to re-load it.


Summary

  • Keep selectors short and simple
  • Avoid layout-thrashing operations
  • Use efficient animation techniques
  • Use external, minified, and cached stylesheets

参与讨论

你可立刻发布并稍后注册。 如果你有帐户,立刻登录发布帖子。

游客
回帖…

帐户

导航

搜索

搜索

配置浏览器推送通知

Chrome (安卓)
  1. 轻敲地址栏旁的锁形图标。
  2. 轻敲权限 → 通知。
  3. 调整你的偏好。
Chrome (台式电脑)
  1. 点击地址栏中的挂锁图标。
  2. 选择网站设置。
  3. 找到通知选项并调整你的偏好。