-
-
Notifications
You must be signed in to change notification settings - Fork 0
Fixed 14 SEO findings across images, fonts, metadata and structured data. #299
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
152c5d4
Served banner and card images through image styles as WebP.
AlexSkrypnyk 0f4a9ed
Wrote search result titles and descriptions to length.
AlexSkrypnyk e8ef7aa
Tightened types on the image dimension resolver and metatag hook.
AlexSkrypnyk 9d044dc
Removed runtime description trimming in favour of authored values.
AlexSkrypnyk e49e331
Addressed code review: token-aware length check, cached and contained…
AlexSkrypnyk 2f85cbf
Restored the stylesheets the overridden components ship.
AlexSkrypnyk 8ae9041
Left the primary navigation untouched.
AlexSkrypnyk 7de5d34
Addressed code review: measured metatag length as plain text.
AlexSkrypnyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| uuid: 199c29c4-f94f-463c-9c3d-34693e08c00f | ||
| langcode: en | ||
| status: true | ||
| dependencies: { } | ||
| name: banner_background | ||
| label: 'Banner background (1920 wide, WebP)' | ||
| effects: | ||
| ebbff644-9a41-4bbb-8aae-5a9e75fc60f9: | ||
| uuid: ebbff644-9a41-4bbb-8aae-5a9e75fc60f9 | ||
| id: image_scale | ||
| weight: 1 | ||
| data: | ||
| width: 1920 | ||
| height: null | ||
| upscale: false | ||
| a4de6937-9de6-4ef4-a664-eaf57d7bd23c: | ||
| uuid: a4de6937-9de6-4ef4-a664-eaf57d7bd23c | ||
| id: image_convert | ||
| weight: 2 | ||
| data: | ||
| extension: webp |
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Front-end performance | ||
|
|
||
| This document describes what the site does to keep pages light and stable while they load. Meta tags and structured data are covered in [SEO](seo.md). | ||
|
|
||
| ## Images always go through an image style | ||
|
|
||
| An image style does two things here: it caps the pixel dimensions, and it converts to WebP. Both matter, because the source files are large brand renders and a 4K PNG hero is several megabytes. | ||
|
|
||
| | Style | Used for | | ||
| |---|---| | ||
| | `banner_background` | The banner background: scaled to 1920 wide, converted to WebP | | ||
| | `civictheme_*` | Cards, campaigns and slides: cropped by the CivicTheme sizes, converted to WebP | | ||
| | `wide` | The banner featured image | | ||
| | `social_share` | Share cards, deliberately **not** converted, because some social crawlers still handle WebP badly | | ||
|
|
||
| CivicTheme resolves both banner images with no image style at all, which yields the URL of the original upload. `_drevops_banner_apply_image_styles()` re-resolves them. It covers the block field and the node field, because the node's value wins when both are set. | ||
|
|
||
| When adding an image style that renders photographic content, copy the `image_convert` effect from `image.style.large.yml`. A style with only a crop effect ships whatever format was uploaded. | ||
|
|
||
| ## Images carry their own dimensions | ||
|
|
||
| Without `width` and `height` a browser cannot reserve space for an image, so every image on the page moves the content under it as it arrives. | ||
|
|
||
| The image component accepts both, but nothing that includes it passes them: the props are built from a media entity, which carries neither. `components/01-atoms/image/image.twig` overrides the CivicTheme component and fills them in through the `do_image_dimensions()` Twig function. | ||
|
|
||
| That function works from the source file and the style's own transform rather than measuring the derivative, so the numbers are right even on the request that generates that derivative for the first time. Vectors have no raster size, so their ratio is read from the `viewBox`; only the ratio matters, since CSS decides the rendered size. | ||
|
|
||
| Components are included from Twig rather than rendered through a render element, so there is no preprocess step and no `#pre_render` to hook. A Twig function called from the template is the only interception point. | ||
|
|
||
| ## Overriding a CivicTheme component | ||
|
|
||
| Drupal matches components by name within an extension, so a same-named component in this theme is a new component rather than an override. The `replaces:` key in the `.component.yml` is what makes it an override: | ||
|
|
||
| ```yaml | ||
| name: Image | ||
| replaces: civictheme:image | ||
| ``` | ||
|
|
||
| Without it the theme's version is simply never used, and the rendered markup keeps saying `data-component-id="civictheme:image"`. | ||
|
|
||
| **Copy the component's stylesheet along with its template.** A component's library is built from the files sitting in its own directory, so once `replaces:` points rendering at the override, the original's `.scss` is no longer part of what loads. An override carrying only a `.twig` renders the right markup with none of the component's CSS, which reads as the component being unstyled rather than as a missing file. `promo` and `pagination` both have one; `image` and `mobile-navigation-trigger` do not. | ||
|
|
||
| Checking the markup is not enough to catch this, because the markup is correct. Compare a computed style against the same element on production, or look at the page. | ||
|
|
||
| ## Fonts are served from this origin | ||
|
|
||
| Lexend and Rubik ship in `assets/fonts/` and are declared in `components/00-base/fonts/fonts.scss`. Nothing is fetched from `fonts.googleapis.com`, which is why the CSP no longer allows it. | ||
|
|
||
| They are declared by hand rather than through CivicTheme's `$ct-fonts` map, because the generator that map feeds emits one `@font-face` per weight and supports neither the variable weight ranges these faces ship as nor the `unicode-range` and `font-display` descriptors a self-hosted face needs. The map still names the families, with an empty `types` list so it emits nothing. | ||
|
|
||
| Only the Latin subsets are preloaded, by `_drevops_attach_font_preloads()`. The extended subsets are needed by a small minority of pages, and a preload the page does not use is a wasted request. | ||
|
|
||
| Replacing a face means replacing the `woff2` files and the `unicode-range` values together. The ranges are Google's own subsetting boundaries and are what keeps a visitor reading only Latin text from downloading the extended file. | ||
|
|
||
| ## The banner background is preloaded | ||
|
|
||
| The banner paints its background from CSS, so the browser cannot discover the file until the stylesheet has been fetched and parsed. On the pages carrying one, that background is the largest contentful paint. | ||
|
|
||
| `_do_base_attach_banner_preload()` emits a `rel="preload"` for it. The URL has to be the one the stylesheet asks for, or the file is fetched twice: the preload resolves the same image style, and skips the whole thing when the file has no derivative. | ||
|
|
||
| ## Verifying a change | ||
|
|
||
| ```bash | ||
| ahoy test-kernel -- --filter=ImageDimensionsExtensionTest | ||
| ``` | ||
|
|
||
| For the rendered end, check that a page's images carry `width` and `height`, that no request goes to `fonts.googleapis.com`, and that image URLs contain `/styles/`. Lighthouse under mobile emulation is the quickest way to see the three metrics these affect: largest contentful paint, cumulative layout shift, and total byte weight. | ||
|
|
||
| ## Related | ||
|
|
||
| - [SEO](seo.md) - meta tags, share cards and structured data | ||
| - [Sitemap](sitemap.md) - XML sitemap coverage and generation |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.