You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MAINT - Defer FontAwesome script to improve performance (#2209)
This pull request:
- Adds "defer" attribute to the script tag that loads the FontAwesome
library
- Consolidates our two custom icon files into one and also loads them
with defer
- Updates documentation to reflect the above two changes
- Excludes images.html from the list of Kitchen Sink pages to check with
Lighthouse.
### Defer
> [!WARNING]
> When this pull request gets released in the next version of the PyData
Sphinx Theme, it will require theme users to update their custom icon
entries in `html_js_files` to include the `defer` attribute (see the
update to the docs page in this pull request).
Without the defer attribute, the entire page has to wait for the
FontAwesome script to be downloaded and executed. Lighthouse identified
this script as the worst offender. With the defer attribute, the page
should be able to load faster.
### Excluding images.html
The reason I'm excluding images.html from Lighthouse is because it
contains images that are hotlinked from Picsum. I think that this is the
reason the Lighthouse performance score comes in too low (below 80).
Because when I examined the Lighthouse report for that page, I saw the
main reason the page failed was because of a slow Largest Contentful
Paint, and when digging into that, the report showed the following
table:
Phase | % of LCP | Timing
-- | -- | --
TTFB | 8% | 460 ms
Load Delay | 89% | 5,350 ms
Load Time | 2% | 110 ms
Render Delay | 2% | 100 ms
I assume that most of that load delay has to do with hotlinking from
Picsum and nothing that we can fix without modifying the Kitchen Sink
pages, which we're not supposed to do since those are generated from a
script.
Using the [Lighthouse score
calculator](https://googlechrome.github.io/lighthouse/scorecalc/#FCP=1665&LCP=6016&TBT=54&CLS=0&SI=2861&TTI=6045&device=mobile&version=12.1.0),
if I substract 5,000 ms from Largest Contentful Paint, the performance
score climbs to 99, which puts it in line with the new performance
scores for the other Kitchen Sink pages.
On the flip side, even though this PR excludes images.html from
Lighthouse, it actually adds more Kitchen Sink pages to the Lighthouse
audit because previously only 5 pages were being checked because the
[default for
maxAutodiscoverUrls](https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/configuration.md)
is 5.
### How I checked this PR
- [x] Looked at the results on the lighthouse-audit CI job
- Inspected the two custom icons in the preview build
- [x] Brave browser, desktop mode
- [x] Brave browser, mobile mode
- [x] Safari, desktop mode
- [x] Firefox, desktop mode
- [x] Checked the preview build to make sure there were no new
JavaScript or other errors in the browser dev tools console log.
- [x] Checked the updated [Header Links docs
page](https://pydata-sphinx-theme--2209.org.readthedocs.build/en/2209/user_guide/header-links.html)
in the preview build
---------
Co-authored-by: Tania Allard <taniar.allard@gmail.com>
#. Remove the existing list of icon definitions and add your own using the same pattern as above:
225
227
226
-
#. ``iconName`` to be one of our choosing
227
-
#. Change the viewbox height and width to match that of your icon
228
-
#. Replace the SVG path string with the path which defines your custom icon
228
+
#. Keep the value of ``prefix`` as "fa-custom"
229
+
#. Set the value of ``iconName`` to a short, sensible, lowercase name for your icon
230
+
#. Change the view box height and width to match that of your icon
231
+
#. For each custom icon you define in the list, increment the Unicode codepoint by 1: ``"e001"``, ``"e002"``, ``"e003"``...
232
+
#. Replace the SVG path string with the path that defines your custom icon
229
233
230
-
#. Add the relative path from your source directory to the custom javascript file to your ``conf.py``:
234
+
#. In ``conf.py``, add the relative path from your source directory to the custom javascript file:
231
235
232
236
.. code:: python
233
237
234
238
html_js_files = [
235
239
...
236
-
"js/pypi-icon.js",
240
+
("js/custom-icons.js", {"defer": "defer"}),
237
241
...
238
242
]
239
243
244
+
.. versionchanged:: v0.17.0
245
+
246
+
``defer`` attribute is required.
247
+
248
+
.. important::
249
+
250
+
Do not add more than one ``custom-icons.js`` file in your ``conf.py``.
251
+
252
+
Each custom icon js file includes a call to ``FontAwesome.library.add()``.
253
+
Your site's JavaScript can only call that function once. In our testing,
254
+
subsequent calls to that function do not load additional icons.
255
+
240
256
#. Set up the icon link in the ``html_theme_options`` as a FontAwesome icon:
241
257
242
258
.. code:: python
@@ -254,7 +270,7 @@ to set up the ``.svg`` to be used as a FontAwesome type icon. This is a fairly s
254
270
...
255
271
]
256
272
257
-
That's it, your icon will now be inserted with the ``<svg>`` tag and not ``<img>``! You can reference your custom FontAwesome icon in CSS using ``fa-<custom-name>``.
273
+
That's it, your icon will now be inserted with the ``<svg>`` tag and not ``<img>``! You can reference your custom FontAwesome icon in CSS using the pattern ``.fa-<iconName>`` , for example ``.fa-pypi``.
258
274
259
275
.. _icon-link-shortcuts:
260
276
@@ -309,3 +325,5 @@ For example, to specify a custom ``target`` and ``rel`` attribute, and to define
309
325
310
326
.. warning::
311
327
This might make your icon links behave unexpectedly and might override the default behavior, so make sure you know what you're doing!
0 commit comments