views:

226

answers:

2

If you don't care about minifying your code, is there a way to get started using the Google Closure library without having to set up a subversion client and use the compiler? The Notepad sample program on Google's website refers to

  <script src="closure-library/base.js" > </script >

Can you simply download closure-library/base.js somewhere and start playing with the UI examples? The Closure Lite quick-start version doesn't appear to include goog.ui

+2  A: 

Take a look at this thread on closure discussion group.

Here is what my html source roughly looks like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"&gt; 
<head> 

<!-- style sheets -->
<link rel="stylesheet" href="/m/myapp/css/style.css">

<!-- closure base -->
<script type="text/javascript" src="/m/google-closure/closure/goog/base.js"></script>

<!-- file containing dependencies specific to the project -->
<script type="text/javascript" src="/m/myapp/my-deps.js"></script>

<!-- main script of my application -->
<script type="text/javascript" src="/m/myapp/main-script.js"></script>

</head>
<body>

<div id="myapp_div"></div>
<script type="text/javascript">
    load_myapp_into("myapp_div");
</script>

</body>
</html>

Write your application code and organize it in any way you like in a directory that maps to /m/myapp url. It is only necessary to specify the main script file. The remaining ones will be loaded according to the dependency map by base.js.

Kind of an interesting feature of closure is that you can move and rename files any way you like since dependency calculator determines for you what comes from where.

The most important part is to calculate the dependency file - my-deps.js here. I still use their old calcdeps.py, but looks like there is a better tool now called depswriter.

After running calcdeps.py you'll most likely have to rewrite paths inside generated deps file, because those paths must be relative to base.js.

Also, even though you may not be interested in the compiler - it is helpful as it points out many errors. I use compiler anyway just for that purpose. Also - closure without a compiler may only be useful for debugging, because download size of uncompiled code may be huge.

Don't pass by closure templates - they are really neat.

Evgeny
for the compiled version you won't need base.js and my-deps.js - just the compiled file
Evgeny
+1  A: 

You can try plovr it is a build tool designed for use with closure.

It comes packed with all the closure tools and the library so you can keep these out of your project folder.

The nice thing about this tool is that you can use it as a server so you can develop your application and by reloading your page, the code gets compiled en is delivered to your application.

It took me about half an hour to understand it and set it up.

Jan