Re: best practices for static resources

2008-06-18 Thread Cliff Wells

On Tue, 2008-06-17 at 19:55 -0700, Shannon -jj Behrens wrote:
 On Mon, Jun 16, 2008 at 2:37 PM, Cliff Wells [EMAIL PROTECTED] wrote:
  On Mon, 2008-06-16 at 14:26 -0700, Cliff Wells wrote:
  On Mon, 2008-06-16 at 13:03 +0200, Wichert Akkerman wrote:
   I am trying to figure out what the best practices for dealing with
   static resources such as CSS, Javascript and images are. With a
   default pylons setup every request goes through two StaticURLParser
   instances and files returned by them do not get any caching headers.
   This is very practical for development but not ideal for a deployment
   For a deployment it would be nice to be able to serve static resources
   from apache or nginx.
  
   How do others do that? Do you use url_for to generate a URL for those
   static resources and have that return a non-paster/pylons URL for
   deployment environments and use the StaticURLParsers when running in
   in development mode? If so, how did you set that up?
 
  I usually just setup Nginx to handle whatever location my static content
  is at.  It doesn't matter if Routes is setup to handle that location as
  the request never reaches Pylons.
 
  Here's an example:
 
  server {
 server_name *.domain.com;
 listen  1.2.3.4:80;
 
 location /public/ {
 root/var/www/myapp;
 expires 30d;
 }
 
 location / {
 proxy_pass http://127.0.0.1:8000$request_uri;
 include/etc/nginx/proxy.conf; # common settings for proxying
 }
  }
 
  In this case, any request for, say /public/css/style.css would map to 
  /var/www/myapp/public/css/style.css.
 
  Regards,
  Cliff
 
 I let Nginx handle the URL if such a file exists.  Otherwise, I let
 Pylons have a shot at it:
 
 ...
 server {
 listen   80;
 server_name  localhost;
 
 location / {
 # Let Nginx handle static content, but proxy to paster for all the
 # dynamic content.
   root/.../wwwaiter/wwwaiter/public;
 if (!-e $request_filename) {
 proxy_pass   http://127.0.0.1:5000;
 }
 }
 
 That way I don't have to include public in my URLs ;-)
 
 (Of course, including public in the URL would probably make life
 easier if I needed to move to something more complicated like a CDN.)

Actually, I tend to use the regex style Jonathon mentioned, but I wanted
the example to be as simple as possible so the solution to the OP's
question would stand out.

Cliff



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: best practices for static resources

2008-06-17 Thread Wichert Akkerman

Previously Cliff Wells wrote:
 On Mon, 2008-06-16 at 13:03 +0200, Wichert Akkerman wrote:
  I am trying to figure out what the best practices for dealing with
  static resources such as CSS, Javascript and images are. With a
  default pylons setup every request goes through two StaticURLParser
  instances and files returned by them do not get any caching headers.
  This is very practical for development but not ideal for a deployment
  For a deployment it would be nice to be able to serve static resources
  from apache or nginx.
  
  How do others do that? Do you use url_for to generate a URL for those
  static resources and have that return a non-paster/pylons URL for
  deployment environments and use the StaticURLParsers when running in
  in development mode? If so, how did you set that up? 
 
 I usually just setup Nginx to handle whatever location my static content
 is at.  It doesn't matter if Routes is setup to handle that location as
 the request never reaches Pylons.

How do you do that during development? Do you hardcode /public/ paths
for static resources everywhere?

I'm starting to think that a best practice setup is something like:

- instead of dumping static resources in / as currently done always
  put the in a private place, similar to how webhelper put its
  javascript files in /javascript/

- setup a separate route for static resources and always use url_for to
  them. I'm not entirely sure routes supports this at the moment.
  
- setup a URLMap in development.ini so you can run the whole site with
  just paster

- for production use a dedicated webserver to serve resources, possibly
  running on another host(name) even

Wichert.

-- 
Wichert Akkerman [EMAIL PROTECTED]It is simple to make things.
http://www.wiggy.net/   It is hard to make things simple.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: best practices for static resources

2008-06-17 Thread Cliff Wells

On Tue, 2008-06-17 at 10:36 +0200, Wichert Akkerman wrote:
 Previously Cliff Wells wrote:
  
  I usually just setup Nginx to handle whatever location my static content
  is at.  It doesn't matter if Routes is setup to handle that location as
  the request never reaches Pylons.
 
 How do you do that during development? Do you hardcode /public/ paths
 for static resources everywhere?

Actually, I never use webhelpers.  I generally use hardcoded paths in my
template and map them in the webserver, but don't see what the issue
would be when using webhelpers.  I don't see the whole process as being
very complicated (nor any need to make it complicated).

Regards,
Cliff


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: best practices for static resources

2008-06-17 Thread Antonio Beamud Montero


El mar, 17-06-2008 a las 04:33 -0700, Cliff Wells escribió:
 On Tue, 2008-06-17 at 10:36 +0200, Wichert Akkerman wrote:
  Previously Cliff Wells wrote:
   
   I usually just setup Nginx to handle whatever location my static content
   is at.  It doesn't matter if Routes is setup to handle that location as
   the request never reaches Pylons.
  
  How do you do that during development? Do you hardcode /public/ paths
  for static resources everywhere?
 
 Actually, I never use webhelpers.  I generally use hardcoded paths in my
 template and map them in the webserver, but don't see what the issue
 would be when using webhelpers.  I don't see the whole process as being
 very complicated (nor any need to make it complicated).

Well, it can be complicated, for example, you are developing with paster
in the url localhost:5000/
But, in production, your web is served under
http://mydomain.com/cool/things/...

I use the url_for for all static content, and with mod_wsgi all is
transparent (thanks G. Dumpleton :), doesn't matter where you put your
web root.

Greetings.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: best practices for static resources

2008-06-17 Thread Wichert Akkerman

Previously Antonio Beamud Montero wrote:
 
 
 El mar, 17-06-2008 a las 04:33 -0700, Cliff Wells escribió:
  On Tue, 2008-06-17 at 10:36 +0200, Wichert Akkerman wrote:
   Previously Cliff Wells wrote:

I usually just setup Nginx to handle whatever location my static content
is at.  It doesn't matter if Routes is setup to handle that location as
the request never reaches Pylons.
   
   How do you do that during development? Do you hardcode /public/ paths
   for static resources everywhere?
  
  Actually, I never use webhelpers.  I generally use hardcoded paths in my
  template and map them in the webserver, but don't see what the issue
  would be when using webhelpers.  I don't see the whole process as being
  very complicated (nor any need to make it complicated).
 
 Well, it can be complicated, for example, you are developing with paster
 in the url localhost:5000/
 But, in production, your web is served under
 http://mydomain.com/cool/things/...

And then you want to scale up even further and have to offload static
resources to another machine. You don't want to have to edit all your
templates to do that.

Wichert.

-- 
Wichert Akkerman [EMAIL PROTECTED]It is simple to make things.
http://www.wiggy.net/   It is hard to make things simple.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: best practices for static resources

2008-06-17 Thread Brandon Singer

On Tue, 2008-06-17 at 14:23 +0200, Antonio Beamud Montero wrote:
 
 I use the url_for for all static content, and with mod_wsgi all is
 transparent (thanks G. Dumpleton :), doesn't matter where you put your
 web root.

I have all my static content urls hardcoded, I was not able to figure
out how to get url_for to work for them. I have all my static content
in /public (served by apache). What do I need to do to get url_for
working?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: best practices for static resources

2008-06-17 Thread Shannon -jj Behrens

On Mon, Jun 16, 2008 at 2:37 PM, Cliff Wells [EMAIL PROTECTED] wrote:
 On Mon, 2008-06-16 at 14:26 -0700, Cliff Wells wrote:
 On Mon, 2008-06-16 at 13:03 +0200, Wichert Akkerman wrote:
  I am trying to figure out what the best practices for dealing with
  static resources such as CSS, Javascript and images are. With a
  default pylons setup every request goes through two StaticURLParser
  instances and files returned by them do not get any caching headers.
  This is very practical for development but not ideal for a deployment
  For a deployment it would be nice to be able to serve static resources
  from apache or nginx.
 
  How do others do that? Do you use url_for to generate a URL for those
  static resources and have that return a non-paster/pylons URL for
  deployment environments and use the StaticURLParsers when running in
  in development mode? If so, how did you set that up?

 I usually just setup Nginx to handle whatever location my static content
 is at.  It doesn't matter if Routes is setup to handle that location as
 the request never reaches Pylons.

 Here's an example:

 server {
server_name *.domain.com;
listen  1.2.3.4:80;

location /public/ {
root/var/www/myapp;
expires 30d;
}

location / {
proxy_pass http://127.0.0.1:8000$request_uri;
include/etc/nginx/proxy.conf; # common settings for proxying
}
 }

 In this case, any request for, say /public/css/style.css would map to 
 /var/www/myapp/public/css/style.css.

 Regards,
 Cliff

I let Nginx handle the URL if such a file exists.  Otherwise, I let
Pylons have a shot at it:

...
server {
listen   80;
server_name  localhost;

location / {
# Let Nginx handle static content, but proxy to paster for all the
# dynamic content.
root/.../wwwaiter/wwwaiter/public;
if (!-e $request_filename) {
proxy_pass   http://127.0.0.1:5000;
}
}

That way I don't have to include public in my URLs ;-)

(Of course, including public in the URL would probably make life
easier if I needed to move to something more complicated like a CDN.)

-jj

-- 
I, for one, welcome our new Facebook overlords!
http://jjinux.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: best practices for static resources

2008-06-16 Thread Cliff Wells

On Mon, 2008-06-16 at 13:03 +0200, Wichert Akkerman wrote:
 I am trying to figure out what the best practices for dealing with
 static resources such as CSS, Javascript and images are. With a
 default pylons setup every request goes through two StaticURLParser
 instances and files returned by them do not get any caching headers.
 This is very practical for development but not ideal for a deployment
 For a deployment it would be nice to be able to serve static resources
 from apache or nginx.
 
 How do others do that? Do you use url_for to generate a URL for those
 static resources and have that return a non-paster/pylons URL for
 deployment environments and use the StaticURLParsers when running in
 in development mode? If so, how did you set that up? 

I usually just setup Nginx to handle whatever location my static content
is at.  It doesn't matter if Routes is setup to handle that location as
the request never reaches Pylons.

Cliff



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: best practices for static resources

2008-06-16 Thread Cliff Wells

On Mon, 2008-06-16 at 14:26 -0700, Cliff Wells wrote:
 On Mon, 2008-06-16 at 13:03 +0200, Wichert Akkerman wrote:
  I am trying to figure out what the best practices for dealing with
  static resources such as CSS, Javascript and images are. With a
  default pylons setup every request goes through two StaticURLParser
  instances and files returned by them do not get any caching headers.
  This is very practical for development but not ideal for a deployment
  For a deployment it would be nice to be able to serve static resources
  from apache or nginx.
  
  How do others do that? Do you use url_for to generate a URL for those
  static resources and have that return a non-paster/pylons URL for
  deployment environments and use the StaticURLParsers when running in
  in development mode? If so, how did you set that up? 
 
 I usually just setup Nginx to handle whatever location my static content
 is at.  It doesn't matter if Routes is setup to handle that location as
 the request never reaches Pylons.

Here's an example:

server {
server_name *.domain.com;
listen  1.2.3.4:80;
   
location /public/ {
root/var/www/myapp;
expires 30d;
}

location / {
proxy_pass http://127.0.0.1:8000$request_uri;
include/etc/nginx/proxy.conf; # common settings for proxying
}
}

In this case, any request for, say /public/css/style.css would map to 
/var/www/myapp/public/css/style.css.

Regards,
Cliff



 Cliff
 
 
 
  


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: best practices for static resources

2008-06-16 Thread Jonathan Vanasco

i do this:

server {
listen 80;
server_name
myapp.com
www.myapp.com
;

access_log  /var/log/nginx/myapp/myapp.com-access.log main;
error_log   /var/log/nginx/myapp/myapp.com-error.log ;

location ~ ^/(_img|_css|_js) {
include /usr/local/nginx/_macros/x-forwarded-
for.conf;
root /home/myapp/myapp_SVN/tags/RELEASE/web/
www.myapp.com;
}

location / {
include /usr/local/nginx/_macros/x-forwarded-
for.conf;
proxy_pass   http://127.0.0.1:5102;
}


}

i put all my static content in _img _css _js buckets , then just serve
those direct.  it's almost the same as Cliff's, just using the regex
functionality.  some people will also set it up to handle file
extensions via regex


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
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
-~--~~~~--~~--~--~---