Use premailer-rails strategies to inline email CSS without network fallback - #2747
Open
mroderick wants to merge 1 commit into
Open
Use premailer-rails strategies to inline email CSS without network fallback#2747mroderick wants to merge 1 commit into
mroderick wants to merge 1 commit into
Conversation
…llback Keep `app/assets/stylesheets/email.css` as a real `.css` file and let premailer-rails inline it at delivery time using the `:filesystem` and `:asset_pipeline` strategies. This loads the stylesheet from the precompiled manifest without ever making an HTTP request to the asset host, so we keep CSS in a proper file while avoiding the stale-cache risk that caused #2634.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Emails previously relied on premailer fetching
/assets/email.cssfromasset_host. After #2715 switched toasset_path("email.css"), the URL is correct but the CSS can still be stale when a proxy caches the resolved URL (see #2634). PR #2722 patched the symptom by inlining social-button colours directly in the template.Solution
Keep
app/assets/stylesheets/email.cssas a real.cssfile and let premailer-rails inline it at delivery time using the:filesystemand:asset_pipelinestrategies. This loads the stylesheet from the precompiled manifest without ever making an HTTP request to the asset host, so we keep CSS in a proper file while avoiding the stale-cache risk.Changes
Premailer::Rails.configwithstrategies: [:filesystem, :asset_pipeline]inconfig/initializers/premailer.rb— removes the:networkfallbackbackground-colorworkaround fromapp/views/shared_mailers/_social.html.haml— premailer inlines the.soc-btn.*rules fromemail.cssbehaves_like_email_with_social_links.rbthat asserts all social-button colours are inlined and no external CSS link appears in the delivered emailshared_mailers/_socialWhat stayed the same
app/assets/stylesheets/email.css— unchangedapp/views/shared_mailers/_header.html.haml— unchanged, still linksemail.cssviaasset_pathVerification
bundle exec rspec spec/mailers/— 75 examples, 0 failuresmake test— 1159 examples, 0 failures