On Aug 14, 2:57 pm, Bradley Wright <[email protected]> wrote:
> I've always used "in-page" configuration for things like this,
> something like:
>
> <script type="text/javascript">
>
> MY_SITE = MY_SITE || {};
>
> MY_SITE.configuration = {
> 'urls': {
> logInUrl = "{{ h.url_for('login') }}"
> ...etc...
> }}
>
> </script>
>
> then obviously you just reference the configuration variable you want:
>
> $.get(MY_SITE.configuration.urls.logInUrl); // etc
I do something similar, though I just save the app prefix instead of
multiple URLs in my global config (though I can see benefits to that
approach):
<script type="text/javascript">
my_namespace.config = {
prefix: '${url("/")}',
// ...
};
</script>
I use the prefix elsewhere to construct URLs:
this.url = my_namespace.config.prefix + 'path/to/cool/stuff';
> FYI the configuration pattern follows along with YUI's stance on not
> polluting the JS environment with lots of global variables - all our
> JS is namespaced under the MY_SITE variable (which obviously changes
> depending on the site).
>
> This allows us to use any context stuff we want, but also keeps
> "dynamic" stuff out of the Javascript, which means we can still follow
> best performance practice and create a single cache-able Javascript
> file (YSlow, PageSpeed etc.).
>
> On Aug 13, 10:56 am, Brian <[email protected]> wrote:
>
> > Right now, I'm working with an application that does a lot of ajax
> > requests, and since we're using RESTful URIs, the URI depends on the
> > session or current context, and we'd like to use the h.url_for()
> > helpers to stick within the framework. Looking around, I haven't found
> > any discussions that really cover this.
>
> > Does anyone have experience/advice for using URIs generated using
> > h.url_for() in javascript files? We have considered placing files in
> > the templates directory and including them, creating a controller that
> > just parses javascript files that need routes, manually building URIs
> > based on javascript attributes of the page. Anyone have comments on a
> > better solution or what worked well for them?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---