Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put SVG images into CSS #2623

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Sep 30, 2024

Since CSS files are often cached, we can take advantage of this to reduce network usage.

Now how it works: we inline the SVG images into a CSS file we generate at compile-time to ensure this file only contains what we need to limit its use but also to generate equivalent Rust types so we know at compile-time that the SVG exists.

I checked on caniuse for mask here: https://caniuse.com/css-masks. It says that more than 89% of current web browsers supports it unprefixed (without -webkit-). With the prefix, it goes up to more than 96%. Just in case, I used both (thanks to HTML variables, we don't need to duplicate the SVG for both mask) so we should be on the safe side with more than 96% of our potential users being able to see the icons.

I compared the HTML size on https://docs.rs/sysinfo/0.30.12/sysinfo/index.html. On current docs.rs, the transferred HTML is 52KB, with this PR is goes down to 40KB.

@GuillaumeGomez GuillaumeGomez requested a review from a team as a code owner September 30, 2024 21:20
@github-actions github-actions bot added the S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed label Sep 30, 2024
src/web/csp.rs Outdated Show resolved Hide resolved
@GuillaumeGomez
Copy link
Member Author

@syphar: Any idea why there are sqlx errors?

build.rs Outdated
@@ -80,11 +84,194 @@ fn main() -> Result<()> {
write_known_targets(out_dir)?;
compile_syntax(out_dir).context("could not compile syntax files")?;

println!("cargo::rustc-check-cfg=cfg(icons_out_dir)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm likely missing something, but where is this cfg ever set?

Or is this just for debugging this build script?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in src/lib.rs to import the generated Rust file.

build.rs Outdated
let css_class = format!("f-a_{icon_name}_{icon_kind}");
css_output.push_str(&format!(
"\
.{css_class} {{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I wonder:

isn't a CSS distribution with the icons something that font-awesome already provides? That we can just use?

@syphar
Copy link
Member

syphar commented Oct 4, 2024

not finished yet with all review, but one bigger question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants