Skip to content

Instantly share code, notes, and snippets.

@saodat1998
Created November 2, 2019 06:38
Show Gist options
  • Save saodat1998/262c1eadf87d077283f35faa5900af40 to your computer and use it in GitHub Desktop.
Save saodat1998/262c1eadf87d077283f35faa5900af40 to your computer and use it in GitHub Desktop.

Css

Tidy and mobile-friendly css needs some requirements to make the website faster:

  • Common css file, which is totally reusable in every page

It is not only styling for the elements that appear in every page, but also, writing the common class names and selectors. In this file you need to create your own markdown and use it in entire development process

  • Separate css file for every template, which is loaded if and only if template is included

Firstly having one css file for a page is not efficient, as it would be bigger in size comparing to smaller css files. Also, small css files gives opportunity to render styles asynchronously as well as conditionally.

  • Define critical (styles the browser needs to render the visible content) and non-critical (styles apply to content that's not immediately visible) css files
<link rel="preload" href="styles.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="styles.css"></noscript>
  • Separate media files to avoid having unused css in different screens

If styling is organized with media queries, it is better to keep them in different files . Because, they are accepted as unused css in improper screens. They do not need to be rendered in every page and every device, oppositely they should be called when there is a need. For instance:

<link href="style.css" rel="stylesheet">
<link href="print.css" rel="stylesheet" media="print">
<link href="other.css" rel="stylesheet" media="(min-width: 40em)">

The media request indicates the type of device and, if necessary, the conditions of the request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment