Violates the Following Content Security Policy Directive: Quick Fix
You turned on a security header, refreshed your site, and now your Google Analytics counter shows zero visitors, your contact form widget is gone, or your custom font reverted to Times New Roman. Open the browser console and there it is, in red: "Refused to load the script... because it violates the following Content Security Policy directive." That exact sentence is the browser's way of telling you the content security policy of your site blocks some resources it doesn't recognize as safe, and it is not broken, it is doing precisely what you asked it to do.
This is a first-aid guide, not a full CSP course. I'm going to show you how to read that error line by line, find the one word inside it that tells you what to fix, and patch the handful of third-party services that trip this error more than anything else: analytics tags, web fonts, video embeds, chat widgets, and payment forms.
What You'll Need Before You Start
Grab these three things first, so you're not hunting for them mid-fix:
- A browser with developer tools open (Chrome, Firefox, or Edge all work; I'll point out where they differ).
- Access to wherever your Content-Security-Policy header actually lives: a hosting control panel, a WordPress security plugin, your server config file, or a header generator like the one on securityheaders.tools' generator.
- The live URL of the page showing the broken widget, font, or script, loaded in front of you right now.
What the error message actually says
Think of the CSP header as a guest list you hand to a bouncer at the door of your site. Every script, image, font, and iframe has to be on that list by name, or the bouncer turns it away at the threshold. The console message is the bouncer telling you exactly who got turned away and which line of the list they failed to match.
Here's a real example of the shape you'll see, pulled from the official reference on content-security-policy.com's blocked resource example:
Refused to load the script 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js'
because it violates the following Content Security Policy directive:
"script-src 'self' blob: filesystem:"
Break that sentence into three parts and it stops being scary. First, the resource type: "script" here, though you'll also see "image," "font," "stylesheet," or "frame." Second, the URL in single quotes: the exact address the browser tried and failed to load. Third, and this is the part that actually matters, the directive name in quotes at the very end: "script-src" in this example.
That word is not a description. It's the literal token you need to find and edit in your header. MDN confirms the same string shows up as violatedDirective when this event fires programmatically, so there's no paraphrasing happening between what you see and what you need to change.
You might also see a slightly different message shape, such as one for an inline script, an inline style, or a blocked eval() call. MDN keeps the full catalog of these variants in its CSP errors and warnings reference, which is worth bookmarking the first time you go hunting for one that looks unfamiliar.
Where to look: console tab vs network tab
The Console tab is where you'll spot this error first, and it's the reliable source across every browser. Open developer tools (F12 on Windows, Cmd+Option+I on Mac), click Console, and reload the page. A blocked resource shows up in red with the exact "Refused to load" text.
Chrome's Network tab gives you a second confirmation: filter for the resource, and a blocked request shows a status of (blocked:csp) instead of a normal HTTP status code. That's handy when you want to see the full request alongside everything else that loaded successfully. Firefox doesn't surface CSP blocks in its Network tab the same way, which is exactly why the Console stays your main tool no matter which browser you debug in.
How to find and fix the CSP directive blocking your resource
Now for the actual repair. Work through these steps in order, and check the "what you should see" line before moving to the next one. If something looks different, the note underneath tells you what likely went wrong.
-
Copy the directive name from the error. In the console message, select just the word before the first space inside the closing quotes (for example, "script-src", not the whole policy string). You should end up with a single token like
script-src,style-src,font-src, orimg-src. If you copied the entire quoted string instead, trim it down; the values after the directive name (like'self') describe what's currently allowed, not what you need to add. -
Open your current Content-Security-Policy header and find that directive. Run your homepage through the securityheaders.tools checker and look at the CSP directives table on the results page, or open your server config or WordPress security plugin settings directly. You should see the directive listed with its current values, such as
script-src 'self'. If the directive isn't listed at all, that's your answer: it's falling back todefault-src, which is usually far more restrictive than you'd expect. -
Compare that value against the blocked URL's domain. Take the domain from the "Refused to load" URL (for example,
cdn.jsdelivr.net) and check whether it appears anywhere in the directive's value. You should see it's clearly missing. If you're not sure whether a similar-looking domain already covers it, remember that CSP wildcards match subdomains, not sibling top-level domains:*.google-analytics.comdoes not covergoogletagmanager.com, even though both belong to Google. -
Add the exact domain to the directive's value. Append the domain (with its scheme, like
https://cdn.jsdelivr.net) to the existing directive value, keeping every domain that was already there. Reload the page and check the console again.You should see the error for that specific resource disappear. If it's still there, double-check you edited the live header and not a cached copy, since some hosting panels and CDNs cache headers for several minutes after a save.
-
Repeat for every remaining red line. One fix often reveals the next, especially with embed-heavy widgets. You should see the console get shorter with each reload. If new errors keep appearing after you thought you were done, skip ahead to the section below on embed chains, because that's almost certainly what's happening.
Common services that get blocked by CSP
Most beginner CSP errors trace back to the same five or six services. Here's the directive and the domain each one actually needs, so you're not guessing at 11pm with a client waiting.
| Service | Directive(s) needed | Domains to add |
|---|---|---|
| Google Analytics / Tag Manager | script-src, img-src, connect-src | googletagmanager.com, *.google-analytics.com, *.analytics.google.com, *.g.doubleclick.net |
| Google Fonts | style-src, font-src | fonts.googleapis.com (style-src), fonts.gstatic.com (font-src) |
| YouTube / Vimeo embeds | frame-src, script-src | youtube.com or player.vimeo.com, plus each vendor's script CDN domain |
| Chat widgets | script-src, connect-src, frame-src | the widget vendor's own CDN and API domains, listed in their docs |
| Stripe / PayPal checkout | script-src, frame-src | js.stripe.com, checkout.stripe.com, or paypal.com and its checkout subdomains |
Google's own guidance for its tag products spells out the analytics row in detail: Tag Manager needs its script source allowed under script-src-elem (or the broader script-src), plus separate entries under img-src and connect-src for the ping and analytics traffic it sends afterward, according to the Google for Developers CSP guide for Tag Manager. Each Google domain has to be listed on its own; a single wildcard entry doesn't quietly cover the rest of the family the way you might expect.
Google Fonts breaks in a way that confuses almost everyone the first time: you add fonts.googleapis.com, the stylesheet loads, and the font still doesn't render. That's because the stylesheet and the actual font files come from two different Google domains. You need fonts.googleapis.com under style-src for the CSS, and fonts.gstatic.com under a separate font-src entry for the font files themselves, as documented in content-security-policy.com's Google Fonts example. Add only one and you've fixed half the problem.
Why adding unsafe-inline usually doesn't fix it
I get some version of this question in nearly every client inbox once a site's CSP goes live: "I added 'unsafe-inline' and the widget is still broken, what am I missing?" Here's the honest answer, and it's the same one that trips up experienced developers, not just beginners.
'unsafe-inline' only changes what happens to inline code: a <script> tag with JavaScript written directly inside it, an inline onclick handler, or a style="..." attribute sitting right on an element. It does nothing at all for an external script loaded from a URL, which is the shape of error you're most likely to hit with analytics tags, font stylesheets, and embed widgets. Adding 'unsafe-inline' to unblock a blocked cdn.jsdelivr.net script is a bit like adding a name to the guest list at the wrong party; the bouncer checking domains at your door never even looks at that list.
Even when 'unsafe-inline' would technically apply, it's a weaker fix than it looks. Modern browsers ignore 'unsafe-inline' entirely in any directive that also contains a valid nonce or hash, which is why the accepted pattern is to add it only as a fallback for very old browsers alongside a nonce, never as the standalone repair. That guidance comes straight from web.dev's strict CSP guide on mitigating cross-site scripting, which also flags a related trap: a broad domain allowlist (the fix in the reference table above) is genuinely easier for a beginner to apply correctly, but it can still be bypassed by an attacker who finds a way to abuse one of the allowed hosts. A nonce-based policy is the more defensible long-term setup once you're past this first-aid stage; the domain allowlist gets your widget working today.
When one fix reveals another error (embed chains)
Video embeds are the classic case where fixing one error just uncovers the next one waiting behind it. A plain-looking Vimeo iframe can quietly load a whole chain of its own scripts underneath, such as a player module, a vendor bundle, and sometimes a Google Cast library for casting video to a TV. Each of those loads from its own domain, and each one needs its own entry in your directive before the embed actually plays. Developers have hit exactly this in public bug trackers for Vimeo's own player library, watching one blocked script get replaced by another after each fix.
The practical habit here: after every change, reload and check the console again before you assume you're finished, or test the next change in report-only mode so nothing breaks while you look. Don't stop at the first "error gone" moment. Widgets built on top of other services tend to load in waves, and CSP will stop each wave at the same door until every domain in the chain is on the list.
Rebuild your header instead of hand-editing it
Once you've patched two or three directives by hand, the header itself tends to sprawl: duplicate domains, a stray wildcard someone added in a hurry, an 'unsafe-inline' nobody remembers adding. Those quick patches are exactly the kind of thing that quietly drops your header's own security grade even while your widgets work again.
Rather than keep hand-editing a growing string, rebuild the policy from scratch in the securityheaders.tools generator, directive by directive, then paste the corrected header back into your server config, hosting panel, or plugin. Once it's live, run the page back through the securityheaders.tools checker to confirm the grade reflects the clean version, not the patchwork one. If you're setting this header through an .htaccess file on an Apache server, htaccess.tools has a plain walkthrough for writing that block correctly, which pairs well with the generator's output. For more background on what each header in the grade actually does, the site's own explainer on security headers is a good next stop.
Frequently Asked Questions
What does refused to load because it violates the following Content Security Policy directive mean?
It means your browser tried to load a script, image, font, or other resource, checked it against the Content-Security-Policy header your site sent, and didn't find that resource's domain listed under the matching directive, so it blocked the load and refused the script or resource entirely. The directive name printed at the end of the message (like script-src or font-src) is the exact setting you need to open and edit, not a general description of the problem.
How do I find which CSP directive blocked a resource?
Open your browser's developer tools, click the Console tab, and reload the page; the blocked resource shows up in red with the full "Refused to load" message, and the directive name sits in quotes at the very end of that line. In Chrome, you can also check the Network tab and look for a status of (blocked:csp) next to the request, which confirms the same block from a second angle. Firefox doesn't show that same Network tab indicator, so the Console remains the most reliable place to look across browsers.
Should I add unsafe-inline to fix it?
Usually not, and it often won't even fix the error you're looking at. 'unsafe-inline' only affects inline scripts and styles written directly in the HTML; it does nothing for an external script blocked because its domain isn't on the allowlist, which is the far more common cause of this error with third-party widgets. Where 'unsafe-inline' would technically apply, most modern browsers ignore it anyway once a valid nonce or hash is present in the same directive, so the more durable fix is adding the specific domain you need or moving to a nonce-based policy rather than reaching for 'unsafe-inline' first.
How do I allow Google Analytics or Fonts under CSP?
For Google Analytics or Tag Manager, add googletagmanager.com under script-src, plus *.google-analytics.com, *.analytics.google.com, and *.g.doubleclick.net under connect-src and img-src as documented in Google's own Tag Manager CSP guide. For Google Fonts, add fonts.googleapis.com under style-src for the stylesheet and fonts.gstatic.com under a separate font-src entry for the actual font files; missing either one leaves the font half-broken even though the page looks like it loaded correctly.