Loading external resources on first load


#1

Hi everyone, I’m creating an app that involves a lot of images, and if I prepare the app with images for all resolutions it get’s too heavy, and if I use a single size and resize them, they get squashed or stretched.
Is there any way to load external resources on first load (optimized for the device resolution) and save them locally?
Is there any tutorial or code snippet on this?

Thanks


#2

By “load external resources on first load” do you mean get them via HTTP? I haven’t seen a tutorial with step-by-step instructions for that but here’s what I would do:

  • Store my assets in AWS S3 (probably a different dir for each “resolution”)
  • Upon application load, use a config var to check “whether or not assets have been downloaded”
  • If assets haven’t been downloaded, check the devices resolution and download the appropriate version of assets from your AWS S3 endpoint.
  • Write the downloaded assets to your app’s documents directory. Use this module in the nativescript API to achieve that
  • Upon completing the previous step, make sure to set the config var to indicate that you already have downloaded assets.