Making the js file a modelglue view means that every request for the js
will be processed by mg & cf, that's a real waste of resources. Including
all your js in the head of your view template is a waste of bandwidth.

As javascript doesn't care where variables are loaded, only that they are
available when needed I'd split all these things up and load them in the
most appropriate place.

   - output user/request specific variables, like username, in the head of
   your page, this could be an included MG view for easy reuse
   - include application level variables via a static js file that is
   generated in ModelGlue's onApplicationStart, this might include a single
   strings.js file or one for each locale you support, eg.
   strings_en.js, including only the appropriate one for the user.
   - include your main js file

This approach has several benefits;

   - reduce the number of requests processed by CF to a minimum
   - keep the size of each request as small as possible
   - you can make the most of browser caching so static files are only
   loaded once.

Forcing the reload of generated static files is simple if you use a param
in your script urls eg. <script src="strings.js?v=1234"> Changing the value
of v will cause the browser to reload the js.

Chris

On 23 January 2012 15:14, marc <[email protected]> wrote:

> It occured to me after posting to make the javascript file a MG view. This
> means the js code should be put in the views folder in one of te locations
> defined in the viewMapping. That javascript code gets included in the head.
> So instead of
>
> <head>
>     <script type="text/javascript" src="/includes/js/myJsFile.js"></script>
> </head>
>
> I'll have
>
> <head>
> <script type="text/javascript" >
>     [... all the javascript formerly included]
> </script>
> </head>
>
> I guess this has the benefity of less requests to the server to retrieve
> external js libraries.
>
>
> Marc
>
> --
> Model-Glue Sites:
> Home Page: http://www.model-glue.com
> Documentation: http://docs.model-glue.com
> Bug Tracker: http://bugs.model-glue.com
> Blog: http://www.model-glue.com/blog
>
> You received this message because you are subscribed to the Google
> Groups "model-glue" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/model-glue?hl=en
>

-- 
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Reply via email to