Is it possible to load some of the JavaScript file from CDN? What is the best way to achieve the same i.e. put some contents on the web server and loading from there. For apple build what is ATS?
2 Answers
Yes, you can surely put some of the javascript from the CDN, one of the example you can check is the 'Stripe.'
I have implemented stripe payment in the Cordova application, and they are providing the live JS URL instead of static javascript file inside the bundle.
For the CDN you can put live URL instead of the local path of the javascript, the only issue it may have is the loading of the CDN JS. If CDN is taking time loading or got some issue, it may create problem in the app at run time
ATS: App transport security, it means you have to use HTTPS else you have to configure your app to allow other unsecured URLs.
In the simplest form you can add it like this:
You have to set the NSAllowsArbitraryLoads key to YES under NSAppTransportSecurity dictionary in your info.plist file.
For more information you can refer:
-
thanks. Does checking flag NSallowArbitraryLoads lead to app rejection – Mantu Nigam Feb 10 '17 at 16:19
-
@MantuNigam No, it will not lead to app reject in the most of the case, i have uploaded around 5 app with `NSallowArbitraryLoads` but none of them are rejected, but there can be 1% change that it may reject based on the URL you are opening, for customization in the ATS you can check ref. links i have put at the bottom. – HardikDG Feb 10 '17 at 16:21
Yes it is possible, though when testing on a PC build environment, you might run into some CORS errors. You won't run into these same errors when building on a phone.
ATS just means you have to be sure to use https.
You can just use a regular script source tag, but be sure to cache the file so it doesn't have to be reloaded every time the app is opened, as then it won't work when the user is offline, or it will be slow every time when they are.

- 63
- 8