module question

31 views
Skip to first unread message

John Munro

unread,
May 22, 2013, 3:46:33 PM5/22/13
to closure-lib...@googlegroups.com
I'm writing a web app that is made up of several pages, all of which make use of the Closure Library.

Should I be compiling all of the js files together into one file or compiling a separate js file for each page?

For example if my uncompiled source consists of page1.js and page2.js should I compile them both down to allpages-compiled.js or should I be compiling them to page1-compiled.js and page2-compiled.js?

In the second case, are modules used to keep from duplicating the Closure Library in each compiled js?

Devraj Mukherjee

unread,
May 23, 2013, 2:26:51 AM5/23/13
to closure-lib...@googlegroups.com
Hi John,

I assume you're using the Closure Compiler to build your JS output. I would recommend compiling one per page, at the end of the compilation Closure Compiler leaves you with only what say Page1.js would need. 



--
 
---
You received this message because you are subscribed to the Google Groups "Closure Library Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-library-d...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ilia Mirkin

unread,
May 23, 2013, 2:58:50 AM5/23/13
to closure-lib...@googlegroups.com
You can use modules for this, basically you would have a "common"
module, and then each page would depend on this common module. Then on
each page, you would load common.js and pageN.js. All the shared
dependencies would be moved into the common.js (which could be cached
across pages), while the per-page specific logic would end up in
pageN.js. Not sure how easy closurebuilder.py makes this, but it's
definitely fairly easy to do with plovr.

Of course, depending on how much page-specific logic there is, it
might be easier to just compile it all into one file and export
functions like "page1Init()" and so on.
Reply all
Reply to author
Forward
0 new messages