Skip to content

Commit

Permalink
refactor!: optimize the resource hints
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 committed Apr 29, 2024
1 parent b77767f commit 2698778
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
15 changes: 8 additions & 7 deletions _data/origin/cors.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# CDNs
# Resource Hints

cdns:
resource_hints:
# Google Fonts
- url: https://fonts.googleapis.com
rel: [preconnect, dns-prefetch]
# Google Fonts download
- url: https://fonts.gstatic.com
args: crossorigin
- url: https://fonts.googleapis.com
rel: [preconnect, dns-prefetch]
attributes: [crossorigin]
# jsDelivr CDN
- url: https://cdn.jsdelivr.net
# polyfill.io for math (cdnjs.cloudflare.com/polyfill)
- url: https://cdnjs.cloudflare.com
rel: [preconnect, dns-prefetch]

# fonts
# Fonts

webfonts: https://fonts.googleapis.com/css2?family=Lato:wght@300;400&family=Source+Sans+Pro:wght@400;600;700;900&display=swap

Expand Down
35 changes: 13 additions & 22 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,25 @@

{% include_cached favicons.html %}

{% if site.resources.ignore_env != jekyll.environment and site.resources.self_hosted %}
<link href="{{ site.data.origin[type].webfonts | relative_url }}" rel="stylesheet">

{% else %}
{% for cdn in site.data.origin[type].cdns %}
<link rel="preconnect" href="{{ cdn.url }}" {{ cdn.args }}>
<link rel="dns-prefetch" href="{{ cdn.url }}" {{ cdn.args }}>
<!-- Resource Hints -->
{% unless site.resources.self_hosted %}
{% for hint in site.data.origin[type].resource_hints %}
{% for rel in hint.rel %}
<link rel="{{ rel }}" href="{{ hint.url }}" {{ hint.attributes | join: ' ' }}>
{% endfor %}
{% endfor %}
{% endunless %}

<link rel="stylesheet" href="{{ site.data.origin[type].webfonts | relative_url }}">
{% endif %}

<!-- GA -->
{% if jekyll.environment == 'production' and site.analytics.google.id != empty and site.analytics.google.id %}
<link rel="preconnect" href="https://www.google-analytics.com" crossorigin="use-credentials">
<link rel="dns-prefetch" href="https://www.google-analytics.com">

<link rel="preconnect" href="https://www.googletagmanager.com" crossorigin="anonymous">
<link rel="dns-prefetch" href="https://www.googletagmanager.com">
{% endif %}
<!-- Theme style -->
<link rel="stylesheet" href="{{ '/assets/css/:THEME.css' | replace: ':THEME', site.theme | relative_url }}">

<!-- Bootstrap -->
<link rel="stylesheet" href="{{ site.data.origin[type].bootstrap.css | relative_url }}">
<!-- Web Font -->
<link rel="stylesheet" href="{{ site.data.origin[type].webfonts | relative_url }}">

<!-- Font Awesome -->
<!-- Font Awesome Icons -->
<link rel="stylesheet" href="{{ site.data.origin[type].fontawesome.css | relative_url }}">

<link rel="stylesheet" href="{{ '/assets/css/:THEME.css' | replace: ':THEME', site.theme | relative_url }}">
<!-- 3rd-party Dependencies -->

{% if site.toc and page.toc %}
<link rel="stylesheet" href="{{ site.data.origin[type].toc.css | relative_url }}">
Expand Down

0 comments on commit 2698778

Please sign in to comment.