<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Async CSS and 'unsafe-inline' in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Async-CSS-and-unsafe-inline/m-p/1124524#M42477</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/346639"&gt;@GRajput&lt;/a&gt;!&lt;/P&gt;&lt;P&gt;I am listing all instances of &lt;STRONG&gt;require_css&lt;/STRONG&gt; to initiate changes.&lt;/P&gt;&lt;P&gt;Thanks a lot!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Mar 2025 15:45:22 GMT</pubDate>
    <dc:creator>paulofdaniel</dc:creator>
    <dc:date>2025-03-19T15:45:22Z</dc:date>
    <item>
      <title>Async CSS and 'unsafe-inline'</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Async-CSS-and-unsafe-inline/m-p/1123855#M42467</link>
      <description>&lt;P&gt;Hi, everyone!&lt;BR /&gt;&lt;BR /&gt;I need to remove 'unsafe-inline' from the Content Security Policy (CSP) and enable Nonce. Right now, I’m searching for all inline scripts inside my templates and modules. While doing this, I discovered that when I import my CSS files with async: true:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{{ require_css(get_asset_url('/css/style.css'), {async: true}) }}&lt;/LI-CODE&gt;&lt;P&gt;the generated code is:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;link class="hs-async-css" rel="stylesheet" href="[...]css/style.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'"&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that the onload attribute does not work without 'unsafe-inline' in CSP, even with Nonce enabled. I could manually update all CSS imports, but since I have hundreds of modules and templates, I’m looking for a better solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have a workaround for this? Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 14:29:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Async-CSS-and-unsafe-inline/m-p/1123855#M42467</guid>
      <dc:creator>paulofdaniel</dc:creator>
      <dc:date>2025-03-18T14:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Async CSS and 'unsafe-inline'</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Async-CSS-and-unsafe-inline/m-p/1124312#M42472</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/434460"&gt;@paulofdaniel&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you’ve removed 'unsafe-inline' from your &lt;STRONG&gt;Content Security Policy (CSP)&lt;/STRONG&gt; and enabled &lt;STRONG&gt;Nonce&lt;/STRONG&gt;, you may notice that some inline scripts, like the onload attribute in your CSS&lt;STRONG&gt; &amp;lt;link&amp;gt;&lt;/STRONG&gt; tags, stop working. This happens because CSP blocks inline scripts unless explicitly allowed.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The onload attribute in a &lt;STRONG&gt;&amp;lt;link&amp;gt;&lt;/STRONG&gt; tag is treated as inline JavaScript, which gets blocked when 'unsafe-inline' is removed from your CSP.&lt;/LI&gt;
&lt;LI&gt;Even if you use a &lt;STRONG&gt;Nonce&lt;/STRONG&gt;, it won’t work because Nonce applies only to &lt;STRONG&gt;&amp;lt;script&amp;gt;&lt;/STRONG&gt; and &lt;STRONG&gt;&amp;lt;style&amp;gt;&lt;/STRONG&gt; tags, not attributes like onload.&lt;/LI&gt;
&lt;LI&gt;Instead of using onload, a better approach is to load CSS dynamically using JavaScript. This keeps your CSP secure while ensuring styles are applied correctly.&lt;/LI&gt;
&lt;LI&gt;Instead of using &lt;STRONG&gt;require_css&lt;/STRONG&gt; with async: true, switch to &lt;STRONG&gt;require_js&lt;/STRONG&gt; to load a global script that handles CSS loading.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN data-sheets-root="1"&gt;I hope this will help you out. Please mark it as &lt;STRONG&gt;Solution Accepted and upvote&lt;/STRONG&gt; to help another Community member.&lt;BR /&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2025 10:22:10 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Async-CSS-and-unsafe-inline/m-p/1124312#M42472</guid>
      <dc:creator>GRajput</dc:creator>
      <dc:date>2025-03-19T10:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Async CSS and 'unsafe-inline'</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Async-CSS-and-unsafe-inline/m-p/1124524#M42477</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/346639"&gt;@GRajput&lt;/a&gt;!&lt;/P&gt;&lt;P&gt;I am listing all instances of &lt;STRONG&gt;require_css&lt;/STRONG&gt; to initiate changes.&lt;/P&gt;&lt;P&gt;Thanks a lot!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2025 15:45:22 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Async-CSS-and-unsafe-inline/m-p/1124524#M42477</guid>
      <dc:creator>paulofdaniel</dc:creator>
      <dc:date>2025-03-19T15:45:22Z</dc:date>
    </item>
  </channel>
</rss>

