Skip to content

Commit

Permalink
Inline defer
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Aug 24, 2020
1 parent 41c99f6 commit 83989e5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ResourceStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ public function generateHtmlIncludes($for = self::TYPE_CSS, int $priority = null
{
$inlineContent = isset($options['_']) ? $options['_'] : null;
$attrs = [];

if(isset($options['defer']) && !isset($options['src']))
{
if(is_int($options['defer']))
{
$attrs['src'] = 'src=\'data:text/javascript;base64,'
. base64_encode('setTimeout(function(){' . $inlineContent . '},' . $options['defer'] . ');') . '\'';
$options['defer'] = true;
}
else
{
$attrs[] = 'src=\'data:text/javascript;base64,' . base64_encode($inlineContent) . '\'';
}
$inlineContent = null;
}

foreach($options as $opt => $optV)
{
if($opt === '_' || $opt === 'rel')
Expand Down

0 comments on commit 83989e5

Please sign in to comment.