1

Background

I am trying to use the PageDown JavaScript library:

Note: the above links to a forked repo. This is the original StackExchange PageDown repo.


But when I try and load 3 JavaScript files using <ltng:require code below:

<aura:component controller="MyController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId"
access="global">

<aura:handler name="init" value="{!this}" action="{!c.doInit}" />

<ltng:require scripts="{!join(',',
                       $Resource.Markdown_Converter,
                       $Resource.Markdown_Sanitizer,
                       $Resource.Markdown_Editor
                       )}"
    afterScriptsLoaded="{!c.afterScriptsLoaded}" />

<!-- other code -->

</aura:component>

But only the first static resource loads and the afterScriptsLoaded method never fires.

Controller.js

({
    doInit: function (component, event, helper) {
        console.log("doInit 1");
    },
    afterScriptsLoaded: function (component, event, helper) {
        console.log("afterScriptsLoaded 1");
    }
})

Each JavaScript static resource file has:

  • cacheControl of Public
  • contentType of application/javascript.

Markdown_Converter.resource-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<StaticResource xmlns="http://soap.sforce.com/2006/04/metadata">
    <cacheControl>Public</cacheControl>
    <contentType>application/javascript</contentType>
</StaticResource>

And there are no errors in the console:

enter image description here

And Network show no 404/403/401's

enter image description here

Questions

  1. What is causing this?
  2. How do I fix it?
3
  • Robs, try checking the network tab for any 404/403/401 errors. Also, check the static resource content type to make sure they are application/javascript. Your code looks just fine from here. I'll try to reproduce, but might take a moment.
    – sfdcfox
    Nov 19, 2018 at 1:45
  • @sfdcfox I've added console log and network log
    – Robs
    Nov 19, 2018 at 10:23
  • @sfdcfox Any thoughts on further lines of investigation?
    – Robs
    Nov 19, 2018 at 19:55

1 Answer 1

2

+Robs, thanks for your detailed description, I was able to load all three files without any problem.

  1. Upload the three files in static resources (I used the UI). enter image description here

  2. Create a component using your unaltered code (and add it to a page): enter image description here

  3. Load the page an look that all files are loaded in developer console. enter image description here

My advise is to look in Setup > Static Resources, and maybe add the files from there, and see what you get.

5
  • I added the files via SFDX and VS Code. Do you think that is the issue?
    – Robs
    Nov 20, 2018 at 0:49
  • OK. I deleted them and re-added and it works now. The only difference I can see is the content type is text/javascript rather than application/javascript
    – Robs
    Nov 20, 2018 at 0:56
  • @Robs Can you tell me what decides the content type? It happens sometimes but how to control this. Nov 20, 2018 at 6:05
  • 1
    @VivekMakkar I created the static resources as application/javascript via VS Code, whereas SF created them as text/javascript when I uploaded via Setup.
    – Robs
    Nov 20, 2018 at 9:04
  • 1
    This is strange, text/javascript is legacy and application/javascript is "modern" mime type. We'll look into it.
    – JF Paradis
    Nov 20, 2018 at 18:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .