bnomei / kirby3-htmlhead

Kirby Plugin for a best-practice HTML Head Element extendable with snippets
https://forum.getkirby.com/t/kirby3-htmlhead-best-practice-html-head-element-extendable-with-snippets/23585
MIT License
20 stars 0 forks source link

Add async scripts #20

Closed seehat closed 3 years ago

seehat commented 3 years ago

Is there a way to output scripts with the async attribute?

If not can you add it?

bnomei commented 3 years ago

the build in snippet has no support for that yet. https://github.com/bnomei/kirby3-htmlhead/blob/master/snippets/htmlhead/script-js.php

but you could create your own snippet and just add its filename with to the plugins config array. like here but indead of htmlhead/script-js you could use your snippets filename.

TIP: thats how you can basically add anything to this plugin. snippets ftw. :D

seehat commented 3 years ago

Ok thank you for your tip! I know this and thought that it would make sense in core, but it's ok for me, when it stays like this.

bnomei commented 3 years ago

@seehat new in https://github.com/bnomei/kirby3-htmlhead/releases/tag/v2.1.9

'htmlhead/script-js' => function ($kirby, $site, $page) {
            return ['files' => [
                // NEW !! ARRAY
                [
                    'src' => 'somescript.js', 
                    'async' => true,
                ],
                '/assets/app.js', // STRING
                'https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.min.js|sha256-4O4pS1SH31ZqrSO2A/2QJTVjTPqVe+jnYgOWUVr7EEc=', // STRING|INTEGRIY
            ]];
        },