Skip to content

Commit

Permalink
Feat: use pre-loaded WebP background image on homepage (#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran authored Nov 16, 2024
2 parents 15c4a9e + fb1b473 commit 11f5380
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions benefits/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<title>{% block page-title %}{% endblock page-title %}| {% translate "Cal-ITP Benefits" %}</title>
{# djlint:on #}

{% block preload %}{% endblock preload %}

<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700" rel="stylesheet" type="text/css">

{% comment %}
Expand Down
6 changes: 6 additions & 0 deletions benefits/core/templates/core/landing.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "core/base.html" %}
{% load i18n %}
{% load static %}

{% block classes %}
{{ block.super | add:" landing" }}
Expand All @@ -10,6 +11,11 @@
{% endblock title %}
{% endblock page-title %}

{% block preload %}
<link rel="preload" as="image" href="{% static 'img/benefits-bg-mobile.webp' %}" media="(width < 992px)" />
<link rel="preload" as="image" href="{% static 'img/benefits-bg-desktop.webp' %}" media="(width >= 992px)">
{% endblock preload %}

{% block main-content %}
<div class="container">
<div class="row align-items-end align-items-lg-center">
Expand Down
6 changes: 4 additions & 2 deletions benefits/static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,9 @@ a.card:focus-visible {

:root {
--landing-main-height: calc(100vh - 80px); /* Header Height (80px) */
--landing-background: url("/static/img/benefits-bg-mobile.jpg") no-repeat
--landing-background: url("/static/img/benefits-bg-mobile.webp") no-repeat
var(--primary-color);
--landing-background-fallback-color: #1a1b16; /* same color the left side of the background image */
--landing-box-background: var(--bs-white);
--landing-box-border: 12px solid var(--primary-color);
--landing-text-color: var(--text-primary-color);
Expand All @@ -854,7 +855,7 @@ a.card:focus-visible {
--landing-main-height: calc(
100vh - 130px
); /* 130px = Header Height (80px) + (Footer Link (50px) */
--landing-background: url("/static/img/benefits-bg-desktop.jpg") no-repeat;
--landing-background: url("/static/img/benefits-bg-desktop.webp") no-repeat;
--landing-box-background: transparent;
--landing-box-border: none;
--landing-text-color: var(--bs-white);
Expand All @@ -865,6 +866,7 @@ a.card:focus-visible {
.landing main#main-content {
background: var(--landing-background);
background-size: cover;
background-color: var(--landing-background-fallback-color);
}

.landing main#main-content .container .row:first-child {
Expand Down
Binary file removed benefits/static/img/benefits-bg-desktop.jpg
Binary file not shown.
Binary file added benefits/static/img/benefits-bg-desktop.webp
Binary file not shown.
Binary file removed benefits/static/img/benefits-bg-mobile.jpg
Binary file not shown.
Binary file added benefits/static/img/benefits-bg-mobile.webp
Binary file not shown.

0 comments on commit 11f5380

Please sign in to comment.