Skip to content

Commit 83989e5

Browse files
committed
Inline defer
1 parent 41c99f6 commit 83989e5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/ResourceStore.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ public function generateHtmlIncludes($for = self::TYPE_CSS, int $priority = null
6262
{
6363
$inlineContent = isset($options['_']) ? $options['_'] : null;
6464
$attrs = [];
65+
66+
if(isset($options['defer']) && !isset($options['src']))
67+
{
68+
if(is_int($options['defer']))
69+
{
70+
$attrs['src'] = 'src=\'data:text/javascript;base64,'
71+
. base64_encode('setTimeout(function(){' . $inlineContent . '},' . $options['defer'] . ');') . '\'';
72+
$options['defer'] = true;
73+
}
74+
else
75+
{
76+
$attrs[] = 'src=\'data:text/javascript;base64,' . base64_encode($inlineContent) . '\'';
77+
}
78+
$inlineContent = null;
79+
}
80+
6581
foreach($options as $opt => $optV)
6682
{
6783
if($opt === '_' || $opt === 'rel')

0 commit comments

Comments
 (0)