Namek Dev
a developer's log

Embedding resource file in Cordova app

July 11, 2014

My latest Cordova application neeeded to read app files such as XML or CSV. During research due to embedding them as resource files I have found that there isn’t needed any platform-specified behaviour.

Embed file

My app is being made in AngularJS so the file structure like this:

  - images
  - scripts
  - styles
  - views

What you need to embed files is just add them into this structure. I like to have folders so there appeared one:


where all my resource files come in.

Read it

$.get 'data/Recipes.csv', (data) ->
    alert data

This is it.

You don’t need any Cordova File API or alikes.

Build it (grunt)

Because I used yeoman, grunt and bower I needed a way to automatically move app/data into dist/data. That’s simple too, just modify copy task:

copy: {
  dist: {
    files: [{
      expand: true,
      dot: true,
      cwd: '<%= %>',
      dest: '<%= yeoman.dist %>',
      src: [
web, javascript
comments powered by Disqus