Performance: Email previews
Email previews affect server response time and initial page load speed when rendering email content in the browser.
def show @email = Email.find(params[:id]) @preview = truncate(strip_tags(@email.full_html_body), length: 300) render html: @preview.html_safe end
def show
@email = Email.find(params[:id])
render html: @email.full_html_body.html_safe
end| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full raw email HTML rendering | High (many nodes) | Multiple reflows | High paint cost | [X] Bad |
| Sanitized truncated preview | Low (few nodes) | Single reflow | Low paint cost | [OK] Good |
def method_name; ...; end syntax.end. Options A, C, and D have syntax errors or invalid Ruby syntax.UserMailerPreview:
def notification_email UserMailer.notification_email(User.find(1)) endWhat will happen when you visit
/rails/mailers/user_mailer/notification_email in the browser?def alert_email UserMailer.alert_email(user) endBut visiting the preview URL gives an error:
undefined local variable or method `user'. What is the fix?user is undefined, meaning it was never assigned a value.user = User.first or similar before calling UserMailer.alert_email(user).UserMailerPreview?Pass the test and this pattern moves unknown