0

I have different css files for each record, which will be stored as a file(ContentVersion). I want to load that css in lwc. But getting this error.

Refused to apply style from '' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

I know we can load the js or css files from static resources, but is it possible to load it from files instead of static resource as the css/js files will be dynamic?

3
  • To understand exactly what you are doing can you put some code? Does your styles start with a comment? If yes please remove the comment and try again. Sep 29 '20 at 5:35
  • You'll need to set the ContentVersion's FileType correctly.
    – sfdcfox
    Sep 29 '20 at 11:08
  • @sfdcfox FileType is CSS, I am fetching the VersionData from apex method. Below is the sample code. Promise.all([ loadStyle(this, data.VersionData) ]); Still no luck. Same error. Sep 30 '20 at 8:19
0

The second parameter must always be a URL. It cannot be plain text that was loaded/parsed directly. You'll want to construct a URL in Apex using Url.getFileFieldUrl:

String fileURL = 
  URL.getFileFieldURL(
    recordId ,
    'VersionData');

Then load that resulting URL in your loadStyle call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.