Skip to content

Commit

Permalink
[5.x] Remove type attribute in nocache replacer (#11373)
Browse files Browse the repository at this point in the history
* Remove script type attribute

* Fix tests
  • Loading branch information
marcorieser authored Jan 21, 2025
1 parent b29a823 commit 1c4bd04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/StaticCaching/Replacers/NoCacheReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function insertJsInHead($contents, $cacher)
Str::position($contents, '</head>'),
])->filter()->min();

$js = "<script type=\"text/javascript\">{$cacher->getNocacheJs()}</script>";
$js = "<script>{$cacher->getNocacheJs()}</script>";

return Str::substrReplace($contents, $js, $insertBefore, 0);
}
Expand All @@ -113,6 +113,6 @@ private function insertJsInBody($contents, $cacher)
{
$js = $cacher->getNocacheJs();

return str_replace('</body>', '<script type="text/javascript">'.$js.'</script></body>', $contents);
return str_replace('</body>', '<script>'.$js.'</script></body>', $contents);
}
}
4 changes: 2 additions & 2 deletions tests/StaticCaching/FullMeasureStaticCachingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function index()
$this->assertEquals(vsprintf('<html><body>1 <span class="nocache" data-nocache="%s">%s</span>%s</body></html>', [
$region->key(),
'<svg>Loading...</svg>',
'<script type="text/javascript">js here</script>',
'<script>js here</script>',
]), file_get_contents($this->dir.'/about_.html'));
}

Expand Down Expand Up @@ -154,7 +154,7 @@ public function it_should_add_the_javascript_if_there_is_a_csrf_token()
// The cached response should have the token placeholder, and the javascript.
$this->assertTrue(file_exists($this->dir.'/about_.html'));
$this->assertEquals(vsprintf('<html><body>STATAMIC_CSRF_TOKEN%s</body></html>', [
'<script type="text/javascript">js here</script>',
'<script>js here</script>',
]), file_get_contents($this->dir.'/about_.html'));
}
}

0 comments on commit 1c4bd04

Please sign in to comment.