10

How to refer External JS files(Google Maps) in Lightning Component without using static resource??

pchittum
  • 19,701
  • 5
  • 54
  • 97
Bala
  • 333
  • 1
  • 4
  • 12

2 Answers2

10

Presently static resource is the only way to use external JS library. It is a security policy.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/apps_csp.htm

Using External JavaScript Libraries

All JavaScript libraries must be uploaded to Salesforce static resources.

Why this is done this way is explained here.

Mahmood
  • 5,984
  • 5
  • 36
  • 60
gaiser
  • 1,360
  • 7
  • 10
0

Lightning has strong idea of encapsulation and communicating with outside world via events.

However there are a few ways to work with outside world. One of the recipies is below:

  1. create a visualforce page or jsp page on Heroku or any other web page you might find convenient, import maps there.

  2. if you are using visualforce page you would not need connected app, iframe would work just fine, because this is the same domain.

  3. if page is on different domain use force:connectedApp in your lightning component this will help with crossdomain issue. create a connected app and point it to this visual force page or jsp page or any other page.

  4. if you need to post data either way,

    • from ligthning component into iframe (connectedApp is literally and iframe)
    • back from within iframe to lightning

    use either canvas SDK or window.postMessage. I find postMessage much simpler.

Pavlonator
  • 538
  • 3
  • 16