Skip to main content
Hi All,

 

Can any salesforce wizard explain the difference between these three.

 

As per my reading and understanding, remote site settings are used for making call to any exernal url from apex controllers whers as to do the same thing from javascript we use CSP whitelisted urls.

 

And Static resources are used to load any external library like javascript libraries.

 

But I feel like there must be some other dimensions to all these as well which I am not getting.

 

So if anybody can break them down to so something more detailed then that would be helpful.

 

Thanks
9 个回答
  1. Jonathan Fox (Cooper Parry) Forum Ambassador
    2020年5月7日 11:55
    Named Credentials: A named credential specifies the URL of a callout endpoint and its required authentication parameters in one definition. To simplify the setup of authenticated callouts, specify a named credential as the callout endpoint. If you instead specify a URL as the callout endpoint, you must register that URL in your org’s remote site settings and handle the authentication yourself. For example, for an Apex callout, your code would need to handle authentication, which can be less secure and especially complicated for OAuth implementations.

     

    Remote Site Settings: When you want to access the external sites in your Salesforce application using callouts, webservices, etc... You need to add that in the Remote Site Settings. This is just a security that force.com platfom is going to check.

     

    Before any Visualforce page, Apex callout, or JavaScript code using XmlHttpRequest in an s-control or custom button can call an external site, that site must be registered in the Remote Site Settings page, or the call will fail. 

     

    Remote Sites are also used for the AJAX Proxy, which lets you get around CORS (Cross-Origin Resource Sharing) security limitations in your browser. While you could use a Named Credential for this purpose (e.g. call a @RemoteAction method or webservice method), the AJAX Proxy can handle large (unlimited?) uploads and downloads, unlike the various limitations that plague the other APIs (1MB, 6MB, 12MB, 15MB are some of the limits you'll encounter using other mechanisms). So there's at least one legitimate case where you'd use a Remote Site. While I do agree that you should consider Named Credentials when possible, there are some practical times when it makes more sense to use a Remote Site and the AJAX Proxy instead.

     

    To reference a JavaScript library, upload it as a static resource and use a <ltng:require> tag in your .cmp or .app markup.

     

    The framework’s content security policy mandates that external JavaScript libraries must be uploaded to Salesforce static resources. For more information on static resources, see “Static Resources” in the Salesforce online help.

     

    You can’t use a <script> tag in a component. This restriction mitigates the risk of cross-site scripting attacks. You can add a <script> tag to an application’s template, which is a special type of component that extends aura:template.

     

    CSP is a W3C standard that defines rules to control the source of content that can be loaded on a page. All CSP rules work at the page level, and apply to all components and libraries. By default, the framework’s headers allow content to be loaded only from secure (HTTPS) URLs and forbid XHR requests from JavaScript.

     

    When you define a CSP Trusted Site, you can add the site’s URL to the list of allowed sites for the following directives in the CSP header.

     

    connect-src

     

    frame-src

     

    img-src

     

    style-src

     

    font-src

     

    media-src

     

    This change to the CSP header directives allows Lightning components to load resources, such as images, styles, and fonts, from the site. It also allows client-side code to make requests to the site.