I'm trying to build a mobile application with phonegap, backbone.js and coffeescript. I want to do something like this :
class MyApplication.Views.EntriesIndex extends Backbone.View
template: load('my/template') //It will load the external file my/template.tpl
render: ->
$(@el).html(@template())
this
I want to load it synchronously. I already seen require.js but I find it's too complicated for this simple think. I seen than I can use JST for a rails application but I don't find how to use it without sprocket and my application must to work on the client side only.
What is the better way to load templates synchronously?
I think the better is to preload it.
My application will be hosted on the client side.
If your application runs as a phonegap app, you might as well include your templates in the HTML:
Explanation of <script type = "text/template"> ... </script>
i load my templates this way:
maybe it`s a solution that works also for you ..
I did this :
And, in my application's initalization :
So I can load template asynchronously and cache it. Obviously, I will do some refactoring and, may be, place it into a JQuery function.
Thanks for yours helps.
Edit
I change my code to do this :
Now I can do this :
This is the javascript's version :
I will probably publish the code on github...