-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 16.01.2012 14:28, schrieb Martin Stein:
> For the current project at work, we are looking into using > require.js (http://requirejs.org/) to combine, modularize and > minify our javascript. So, basically, we need to have a server-side > build step before serving our static files. Our plan is as > follows: > > - have our pre-build javascript files in the usual '/static' > directory - put the results from require's optimizer to a > '/static-build' directory. (The require.js docs recommend a > separate directory.) > > Depending on development or production scenario (taken from .ini- > file), the static files should be served from one or the other > directory. In a project we bypass the webapp completely for /static and let apache deliver the files from the /static directory on disk. We also set cache headers in the apache configuration. ..Carsten > However, so far I don't see a nice approach to this. When we > started the project, we used the normal Pyramid approach in our > templates. In our __init__.py, we have something like: > > config.add_static_view('static', 'myproject:static', > cache_max_age=3600) > > In the jinja-template, we created the links with > > <script src="{{request.static_url('myproject:static/js/ > application.js')}}" type="text/javascript"></script> > > But if the directory changes from 'static' to 'static-build', we > would have to change all our static_url(..) calls. Is there a way > to make the resource 'myproject:static' refer to a different > directory, depending on .ini configuration? > > One approach would be to read the resource directory from the .ini > file and add the static view like this: > > config.add_static_view('static', RESOURCE_FROM_INI, > cache_max_age=3600) > > Then, you could refer to the files like this: > > <script src="{{ request.script_name }}/js/application.js'" > type="text/ javascript"></script> > > (note that you need the 'script_name', because on the production > server your application might be deployed under a URL prefix). But > the 'request.script_name' approach looks kind of hacky to me and it > means we'd have to replace all our static_url(..)-calls. Do you see > another way to do this elegantly? > > The trend for larger javascript-heavy apps seems to be going > towards require.js, so I think a nice solution for this problem > will be interesting for lots of people. > > Thanks, Martin > - -- Carsten Senger - Schumannstr. 38 - 65193 Wiesbaden [email protected] - (0611) 5324176 PGP: gpg --recv-keys --keyserver hkp://subkeys.pgp.net 0xE374C75A -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJPFFbxAAoJEAOSv+HjdMdaEOsIAIBvOrh3431d5wH0qZP8YDcl FMiRQ6RDRORcxNw6EmphyJ5VD9GpScOLLz026Ed60eUVDS+f6fH08qbAyOR2h3n9 Lbdt68JxSCL36CA2urvIpsH4OoU3d/Du/VbZ0wthTTIBbEZ/rfemfiYWAqlQfOJf /PB8bOViWdphIfgAiQN4d3wPf/1eIvxG1ECiWkyxKpSAUPKMSLPfRExEtkbfFGqr u0M9K4uYn1qu7yFymA7q++o0MYktrXzYGNGsauVYybgGnVduM2nQknTpuho2XA8g KrXsj0ckjOyQgPYZs9Ag8mU8So4aCwsi3fPK8HDWbL6dlwq26V21ScGpgN7ARMg= =AfCA -----END PGP SIGNATURE----- -- 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.
