最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Google Closure Templates with jQuery - Stack Overflow

programmeradmin1浏览0评论

We are starting to create an application using JavaScript and HTML5 which will use rest API to access server resources taking the advantage of jQuery awesomeness and easiness which our dev team is already fortable with. This application is going to be made multilingual. We had decided later that we will write our DOM using JavaScript which will allow us the flexibility to use our UI bits for integration with our other applications and will create our own widgets using jQuery UI widgets. Then by just adding a script tag referencing JavaScript file in a relevant page of our other application, we will have most of our integration for that particular feature done.

Because it takes lot of amount of coding for creating DOM using JavaScript, we started looking in search of tools which will help us easily convert HTML to JavaScript for creation of UI and hence Google Closure Templates came in.

At this time what I thought of was, using Google closure for writing the UI DOM bit as it can quickly give me JavaScript for my DOM and then for other JavaScript (i.e. for server side munication and for other UI logic like changing of UI once got response from the server and x should change to y on click of z kind of things) which needs to be handwritten, I should use jQuery which is easy to write.

But after looking at this question, I see that both are pared against each other and it left me wondering on few things.

  1. If I go by what I've thought of doing then, will I be able to call the functions generated by Google Closure in my jQuery widgets to render the UI?

  2. If I leave jQuery and just use Google Closure will it be enough for my requirements?

  3. As I started reading Google Closure documentation, I found that it has a whole new world of it's own and learning curve is involved. How much it is? If it is not much, then our team of 5 devs will be ready to learn it.

On 2 and 3, it would be great if anyone who has already used it can provide some insight.

Note:- Just in case if it has any relevance, we are working on Microsoft .NET stack for server side.

We are starting to create an application using JavaScript and HTML5 which will use rest API to access server resources taking the advantage of jQuery awesomeness and easiness which our dev team is already fortable with. This application is going to be made multilingual. We had decided later that we will write our DOM using JavaScript which will allow us the flexibility to use our UI bits for integration with our other applications and will create our own widgets using jQuery UI widgets. Then by just adding a script tag referencing JavaScript file in a relevant page of our other application, we will have most of our integration for that particular feature done.

Because it takes lot of amount of coding for creating DOM using JavaScript, we started looking in search of tools which will help us easily convert HTML to JavaScript for creation of UI and hence Google Closure Templates came in.

At this time what I thought of was, using Google closure for writing the UI DOM bit as it can quickly give me JavaScript for my DOM and then for other JavaScript (i.e. for server side munication and for other UI logic like changing of UI once got response from the server and x should change to y on click of z kind of things) which needs to be handwritten, I should use jQuery which is easy to write.

But after looking at this question, I see that both are pared against each other and it left me wondering on few things.

  1. If I go by what I've thought of doing then, will I be able to call the functions generated by Google Closure in my jQuery widgets to render the UI?

  2. If I leave jQuery and just use Google Closure will it be enough for my requirements?

  3. As I started reading Google Closure documentation, I found that it has a whole new world of it's own and learning curve is involved. How much it is? If it is not much, then our team of 5 devs will be ready to learn it.

On 2 and 3, it would be great if anyone who has already used it can provide some insight.

Note:- Just in case if it has any relevance, we are working on Microsoft .NET stack for server side.

Share Improve this question edited May 23, 2017 at 11:55 CommunityBot 11 silver badge asked Jul 29, 2011 at 9:01 IsmailSIsmailS 10.9k22 gold badges86 silver badges141 bronze badges 6
  • Have you considered jquery templates? The Goog library is an entire framework in it's own right and is more plex then jQuery. – Raynos Commented Jul 29, 2011 at 9:23
  • What do you want to do? Google Closure Templates and Google Closure Library are different pieces of software that do not share any dependency. – marc Commented Jul 29, 2011 at 13:35
  • @marc, so does that mean, I will be able to call the functions generated by Google Closure Templates in my jQuery widgets to render the UI? – IsmailS Commented Aug 1, 2011 at 5:43
  • imho yes, because it has nothing to do with the library – marc Commented Aug 1, 2011 at 8:07
  • 1 Yes, I think this is a way to go that wont cause problems. – marc Commented Aug 2, 2011 at 5:21
 |  Show 1 more ment

1 Answer 1

Reset to default 8

Closure Library and Closure Templates do not depend on one another, so you can certainly use Closure Templates with jQuery without pulling in the Closure Library or the Closure Compiler. To use Templates with jQuery, you translate your Closure Template files (aka "Soy" files) using SoyToJsSrcCompiler.jar as described in the documentation. Then you will have one JavaScript file for each Soy file where each JavaScript file contains one function per template defined in the corresponding Soy file.

To use the generated JavaScript functions, you must also include soyutils.js, which is a set of utilities required by the generated functions. Therefore, your production system should include the following JavaScript files concatenated/minified in this order:

  • soyutils.js
  • JavaScript generated from Soy
  • jQuery library
  • Your application code, which presumably depends on both jQuery and your template functions.

Getting up to speed on Closure Templates is considerably easier than learning the Library or the Compiler, so I'm sure that your dev team can pick it up quickly. I believe the online documentation is thorough without being overwhelming, so the syntax and usage should not take long to learn.

Note that if you decide to use the Closure Library instead of jQuery at some point, you should include soyutils_usegoog.js instead of soyutils.js. Though if you decide to rewrite your application logic to depend on Closure Library instead of jQuery after you have a substantial amount of code, this small change will likely be the least of your concerns! That is, I'm sure you could ultimately write your entire application using Google Closure, but migrating from one JavaScript library to another for a large application will likely require so many code changes that you may be too intimidated to take on the migration.

发布评论

评论列表(0)

  1. 暂无评论