4

I'm following the "Lightning Components Developer's Guide" and when I try to preview my app I get always a CSP (Content Security Policy) error that the css file is blocked for loading. I've read a similar question about it with REST API and Lightning Components How to call a Salesforce REST URL from Lightning Component? but is there another workaround then creating an APEX controller for loading just a css file?

Samuel Moyson
  • 313
  • 2
  • 9

1 Answers1

2

Apex is not required and is not going to help for web content - you simply need to create a Static Resource in your org and upload the Bootstrap library. You can then reference /resource/yourBootstrapStaticResourceNameHere etc. Static Resources are served from the same domain as your app/components and therefore satisfy our CSP policy.

Doug Chasman
  • 10,054
  • 23
  • 36
  • Here is a pattern to make sure things like font references work when Bootstrap is setup as a static resource. – Keith C Nov 26 '14 at 14:06
  • 1
    FYI: The Lightning Components Developer's Guide seems to indicate external CSS can be loaded: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apps_css.htm – Peter Knolle Nov 26 '14 at 14:08
  • Thanks! I wrote resourc instead of resource in my code, now it' working! – Samuel Moyson Nov 26 '14 at 14:46
  • The LC Dev guide is derived from the Aura open source docs and this is a hold over from there that apparantly has not been adjusted to line up with Force.com's CSP enforcement. I've brought this to the LC doc folks attention and will get it corrected - thanks – Doug Chasman Nov 26 '14 at 15:40
  • And what about Lightning Tabs? Could it be that css is not working there? – Samuel Moyson Nov 28 '14 at 07:41
  • Lightning Tabs can only reference components and components can't include or – Doug Chasman Nov 28 '14 at 12:32