Skip to content

Split print styles to separate stylesheet#10419

Merged
aduth merged 1 commit intomainfrom
aduth-print-stylesheet
Apr 12, 2024
Merged

Split print styles to separate stylesheet#10419
aduth merged 1 commit intomainfrom
aduth-print-stylesheet

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Apr 12, 2024

🛠 Summary of changes

Splits print styles to separate stylesheet, so that it's only loaded when printing.

Why?

  • Reduce size of stylesheet for users browsing the web version of the site

Performance Impact:

NODE_ENV=production yarn build:css && brotli-size app/assets/builds/application.css

Before: 18.4 kB
After: 18.3 kB
Diff: -0.1 kB (-0.5%)

📜 Testing Plan

Verify that print styles are preserved:

  1. Go to http://localhost:3000
  2. Press Cmd+P
  3. Observe that the preview does not include the "Submit" button

Verify that the print stylesheet is not preloaded:

  1. In a separate Terminal process, run: curl -I --silent http://localhost:3000 | grep 'link:'
  2. Verify that the output does not include print.css

changelog: Internal, Performance, Reduce size of common application stylesheet
<%= preload_link_tag font_url('public-sans/PublicSans-Regular.woff2') %>
<%= render_stylesheet_once_tags %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= stylesheet_link_tag 'application' %>
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make a difference to keep the media: 'all' or is that basically the default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's redundant. I couldn't find anything which explicitly states that it's the default, but this documents the distinction between print and screen, and all as matching the union. I assume we meant it as applying the same as if it weren't applied at all.

https://drafts.csswg.org/mediaqueries/#media-types

@aduth aduth merged commit 593f3a5 into main Apr 12, 2024
@aduth aduth deleted the aduth-print-stylesheet branch April 12, 2024 16:40
@mitchellhenke mitchellhenke mentioned this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants