Skip to content

Commit

Permalink
Fix for critical CSS and added imager and minify configs
Browse files Browse the repository at this point in the history
  • Loading branch information
bymayo committed Jun 19, 2018
1 parent 16855ba commit 0b03328
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 44 deletions.
3 changes: 3 additions & 0 deletions config/imager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
return array(
);
4 changes: 2 additions & 2 deletions config/minify.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
return [
return array(
'disableDevmodeMinifying' => true
];
);
7 changes: 7 additions & 0 deletions templates/_404.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
{% endcache %}
{% endblock %}

{# ------- Critical ------- #}

{% block criticalCss %}
{%- spaceless -%}
{%- endspaceless -%}
{% endblock %}

{# ------- Inline ------- #}

{% block inlineCss %}
Expand Down
7 changes: 7 additions & 0 deletions templates/_410.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
{% endcache %}
{% endblock %}

{# ------- Critical ------- #}

{% block criticalCss %}
{%- spaceless -%}
{%- endspaceless -%}
{% endblock %}

{# ------- Inline ------- #}

{% block inlineCss %}
Expand Down
7 changes: 7 additions & 0 deletions templates/_503.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
{% endcache %}
{% endblock %}

{# ------- Critical ------- #}

{% block criticalCss %}
{%- spaceless -%}
{%- endspaceless -%}
{% endblock %}

{# ------- Inline ------- #}

{% block inlineCss %}
Expand Down
11 changes: 4 additions & 7 deletions templates/_blocks/block.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{%- cache -%}
{%- minify -%}
{% if entry is defined and entry.matrix.block is defined %}
{# Block #}
{% endif %}
{%- endminify -%}
{%- endcache -%}
{% cache %}
{% minify %}
{% endminify %}
{% endcache %}
66 changes: 35 additions & 31 deletions templates/_layout/base.twig
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
{%- minify -%}
{% minify %}

{% import '_partials/macros' as macro %}
{% import '_partials/macros' as macro %}

<!doctype html>
<html class="no-js" lang="{{ craft.app.language|slice(0,2) }}">
<head>
<!doctype html>
<html class="no-js" lang="{{ craft.app.language|slice(0,2) }}">
<head>

<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

{# Favicons #}
{{ source('_partials/favicons', ignore_missing = true) }}
{# Favicons #}
{{ source('_partials/favicons', ignore_missing = true) }}

{# Inline / Critical CSS #}
{% if block('inlineCss') is defined %}
<style>
{% block inlineCss %}{% endblock %}
</style>
{% endif %}
{# Inline / Critical CSS #}
{% if
block('inlineCss')|length or
block('criticalCss')|length
%}
<style>
{% block criticalCss %}{% endblock %}
{% block inlineCss %}{% endblock %}
</style>
{% endif %}

{# CSS #}
<link rel="preload" href="{{ rev('/dist/app.css') }}" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript>
<link rel="stylesheet" href="{{ rev('/dist/app.css') }}">
</noscript>
{# CSS #}
<link rel="{{ block('criticalCss')|length ? 'preload' : 'stylesheet' }}" href="{{ rev('/dist/app.css') }}" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript>
<link rel="stylesheet" href="{{ rev('/dist/app.css') }}">
</noscript>

</head>
</head>

<body>
<body>

{% block body %}{% endblock %}
{% block body %}{% endblock %}

{# Javascript #}
<script src="{{ rev('/dist/app.js') }}"></script>
{# Javascript #}
<script src="{{ rev('/dist/app.js') }}"></script>

{# Inline Javascript#}
{% block inlineJs %}{% endblock %}
{# Inline Javascript#}
{% block inlineJs %}{% endblock %}

</body>
</body>

</html>
</html>

{%- endminify -%}
{% endminify %}
File renamed without changes.
17 changes: 13 additions & 4 deletions templates/_page/types/page.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@
{% block content %}

{% cache %}
{% for block in entry.matrix %}
{% include '_blocks/' ~ block.type %}
{% endfor %}
{#
{% for block in entry.matrix %}
{% include '_blocks/' ~ block.type %}
{% endfor %}
#}
{% endcache %}

{% endblock %}

{# ------- Critical ------- #}

{% block criticalCss %}
{%- spaceless -%}
{{ source (entry.slug ~ '.css', ignore_missing = true) }}
{%- endspaceless -%}
{% endblock %}

{# ------- Inline ------- #}

{% block inlineCss %}
{{ source (entry.slug ~ '.css', ignore_missing = true) }}
{% endblock %}

{% block inlineJs %}
Expand Down

0 comments on commit 0b03328

Please sign in to comment.