Serving static files with Grails

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Serving static files with Grails

Babelex
How does one serve static files (html,images,js.css, binaries etc..) in rails?

Obviously in the deployed situation this gets handles by Apache, but
wneh developing on a local workstation what is the best policy to
include thise static files?

--
regards
Al
http://www.folknology.com/index.html
#OpenSource means free to innovate#

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

JamesPage


On 5/15/07, Babelex <[hidden email]> wrote:
How does one serve static files (html,images,js.css, binaries etc..) in rails?

Do you not mean grails?

Obviously in the deployed situation this gets handles by Apache, but
wneh developing on a local workstation what is the best policy to
include thise static files?

If it is grails and not rails then you want to put them into a subfolder of web-app.... If want to use Apache instead to handle static files then you want to use the Static Resources Plugin
http://grails.codehaus.org/Static+Resources+Plugin

You do not have to worry about the different modes -production - development... The wonders of grails does all that magic for you..

Hope this helps

james
--
regards
Al
http://www.folknology.com/index.html
#OpenSource means free to innovate#

---------------------------------------------------------------------
To unsubscribe from this list please visit:

     http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Babelex
Excellent thanks James and yes I did mean Grails,
'rails' must have been a freudian slip!!

I will take a look at the link for the static resources plugin.

--
regards
Al
http://www.folknology.com/index.html
#OpenSource means free to innovate#

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Babelex
Actually I just too a look at the static resources plugin and in my
case it won't work because it runs on a different port (8088). Given
that some of the static resources are HTML files with ajax embedded in
them calling the Grails context it won't work. This is becase ajax
relies on same-origin policy which effects domain/portand and protocol
compared to html page source.

Any way around this, can it be run under the same port as Grails with
a different context?

--
regards
Al
http://www.folknology.com/index.html
#OpenSource means free to innovate#

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Eric Everman
In reply to this post by Babelex
Just stick your static content in the web-app folder - it will work.  You can also place jsp and gsp files in there.  Note that the css files referred to in your layout template are static files in a subdirectory of web-app and they work fine.

The only oddity that I've noticed is that the normal site-mesh templating does not work for pages that are not in the Views directory and that grails tags generated links to content in the root directory do not work correctly.

links bug:  http://jira.codehaus.org/browse/GRAILS-1140


Babelex wrote
How does one serve static files (html,images,js.css, binaries etc..) in rails?

Obviously in the deployed situation this gets handles by Apache, but
wneh developing on a local workstation what is the best policy to
include thise static files?

--
regards
Al
http://www.folknology.com/index.html
#OpenSource means free to innovate#

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Babelex
Thanks Eric

On 5/16/07, Eric Everman <[hidden email]> wrote:

>
> Just stick your static content in the web-app folder - it will work.  You can
> also place jsp and gsp files in there.  Note that the css files referred to
> in your layout template are static files in a subdirectory of web-app and
> they work fine.
>
> The only oddity that I've noticed is that the normal site-mesh templating
> does not work for pages that are not in the Views directory and that grails
> tags generated links to content in the root directory do not work correctly.
>
Yup that works although I had to copy the entire directory structure
as it didn't seem to follow sym links.

--
regards
Al
http://www.folknology.com/index.html
#OpenSource means free to innovate#

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

hamishagain@dcs.shef.ac.uk
In reply to this post by JamesPage
hi

James Page wrote:

> If it is grails and not rails then you want to put them into a subfolder
> of web-app.... If want to use Apache instead to handle static files then
> you want to use the Static Resources Plugin
> http://grails.codehaus.org/Static+Resources+Plugin <tatic+Resources+Plugin>

can you tell me how I can get this? none of the links at

http://svn.grails-plugins.codehaus.org/browse/grails-plugins/grails-staticresources

seem to contain the plugin

tnx
--
Hamish
http://www.dcs.shef.ac.uk/~hamish/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

graemer
http://svn.grails-plugins.codehaus.org/browse/~raw,r=75/grails-plugins/grails-staticresources/grails-StaticResources-0.3.zip

Cheers

On 5/16/07, Hamish Cunningham <[hidden email]> wrote:

> hi
>
> James Page wrote:
>
> > If it is grails and not rails then you want to put them into a subfolder
> > of web-app.... If want to use Apache instead to handle static files then
> > you want to use the Static Resources Plugin
> > http://grails.codehaus.org/Static+Resources+Plugin <tatic+Resources+Plugin>
>
> can you tell me how I can get this? none of the links at
>
> http://svn.grails-plugins.codehaus.org/browse/grails-plugins/grails-staticresources
>
> seem to contain the plugin
>
> tnx
> --
> Hamish
> http://www.dcs.shef.ac.uk/~hamish/
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Marc Palmer Local
In reply to this post by Babelex

On 16 May 2007, at 00:31, Babelex wrote:

> Actually I just too a look at the static resources plugin and in my
> case it won't work because it runs on a different port (8088). Given
> that some of the static resources are HTML files with ajax embedded in
> them calling the Grails context it won't work. This is becase ajax
> relies on same-origin policy which effects domain/portand and protocol
> compared to html page source.
>
> Any way around this, can it be run under the same port as Grails with
> a different context?

I tried to make it do this / use Jetty but there are weird classpath  
problems. It might be possible to circumvent them but it was too much  
hard work.

Your solution will be to use a Squid reverse proxy both locally and  
on the live site I think. We are moving to this kind of solution. You  
can still use StaticResourcesPlugin to do this, but change the URIs  
used depending on your env in ApplicationBootStrap - that way you can  
still use g:resourceLink

I'll be working on this in the next 2 weeks as we have a site that  
requires it.

Marc



---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Marc Palmer Local
In reply to this post by Eric Everman

On 16 May 2007, at 02:53, Eric Everman wrote:

>
> Just stick your static content in the web-app folder - it will  
> work.  You can
> also place jsp and gsp files in there.  Note that the css files  
> referred to
> in your layout template are static files in a subdirectory of web-
> app and
> they work fine.

This is slow in production for high load sites. Its fine for low  
traffic / "toy" sites.

Marc




---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Babelex
Thanks Marc, I'm using Erics hack for now, but will be interested in
any enhancements you make going forward with the static resources
plugin as it could make my life easier still.

On 5/16/07, Marc Palmer <[hidden email]> wrote:

>
> On 16 May 2007, at 02:53, Eric Everman wrote:
>
> >
> > Just stick your static content in the web-app folder - it will
> > work.  You can
> > also place jsp and gsp files in there.  Note that the css files
> > referred to
> > in your layout template are static files in a subdirectory of web-
> > app and
> > they work fine.
>
> This is slow in production for high load sites. Its fine for low
> traffic / "toy" sites.
>
> Marc
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
regards
Al
http://www.folknology.com/index.html
#OpenSource means free to innovate#

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

felipenasc
In reply to this post by Marc Palmer Local
Marc,
 
I am developing a high traficc site. What do you suggest is the best solution for this problem now?
1) Use Squid reverse proxy
2) Use static resources plugin?
3) other..
 
As I am in the middle of the development, have the two options to implement. Do you suggest one over the other?
 
Tks
Felipe

 
On 5/16/07, Marc Palmer <[hidden email]> wrote:

On 16 May 2007, at 00:31, Babelex wrote:

> Actually I just too a look at the static resources plugin and in my
> case it won't work because it runs on a different port (8088). Given
> that some of the static resources are HTML files with ajax embedded in
> them calling the Grails context it won't work. This is becase ajax
> relies on same-origin policy which effects domain/portand and protocol
> compared to html page source.
>
> Any way around this, can it be run under the same port as Grails with
> a different context?

I tried to make it do this / use Jetty but there are weird classpath
problems. It might be possible to circumvent them but it was too much
hard work.

Your solution will be to use a Squid reverse proxy both locally and
on the live site I think. We are moving to this kind of solution. You
can still use StaticResourcesPlugin to do this, but change the URIs
used depending on your env in ApplicationBootStrap - that way you can
still use g:resourceLink

I'll be working on this in the next 2 weeks as we have a site that
requires it.

Marc



---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Marc Palmer Local

On 16 May 2007, at 23:19, Felipe Nascimento wrote:

> Marc,
>
> I am developing a high traficc site. What do you suggest is the  
> best solution for this problem now?
> 1) Use Squid reverse proxy
> 2) Use static resources plugin?
> 3) other..
>
> As I am in the middle of the development, have the two options to  
> implement. Do you suggest one over the other?
>

Well this is not a big development decision, it hardly affects your  
code - it is a deployment decision. StaticResourcesPlugin gives you  
the resourceLinkTo tag which you can use without the internal HTTP  
server  - just need to comment out that bit of code and tweak the  
values for production env.

If you use the plugin as it is now, it expects the production  
resources to be on the same server and port on the production system.  
A networking friend of mine rightly pointed out that to handle high  
peaks of traffic you want to take all static resource serving off the  
main application server, so that there is not competition for  
resources (CPU/RAM/Swap) between your static resources server (apache  
or other) and your app (Tomcat or other).

We will be trying Squid/a standalone Apache out on this project,  
running on a separate server. We will still use resourceLinkTo so  
that we can link to the caching server for images etc and these will  
stay in a separate static content folder and not be in the web-app,  
as we need to be able to update these resources without tweaking/
redeploying the webapp.

Live server tweaks to an expanded webapp are 100% evil in my view and  
that is why we want to move all our future Grails apps to have no  
GSPs or static content loaded from the webapp.

Marc


 

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

hamishagain@dcs.shef.ac.uk
In reply to this post by graemer
hi

Graeme Rocher wrote:
> http://svn.grails-plugins.codehaus.org/browse/~raw,r=75/grails-plugins/grails-staticresources/grails-StaticResources-0.3.zip 

thanks; I got it now. I can't get it to run though (grails 0.5, java 1.5)

I did: grails install-plugin on the URL above, which seemed to work, but then
when I ran run-app I got a compile exception. I tried grails upgrade within
the plugin directory and run-app again, but then I got a conflict between two
versions of a class:

./plugins/StaticResources-0.3/plugins/core/grails-app/taglib/RenderTagLib.groovy
./plugins/core/grails-app/taglib/RenderTagLib.groovy]

so I removed the StaticResources...core directory, at which point my compile
exception came back, complaining about a .zip file (!):


     [javac] Compiling 1 source file to
/home/hamish/ext/sins/StaticResources-0.3/web-app/WEB-INF/classes
error: error reading
/home/hamish/ext/sins/StaticResources-0.3/web-app/WEB-INF/classes/log4j.development.properties;
error in opening zip file
Note: /home/hamish/ext/sins/StaticResources-0.3/src/java/NanoHTTPD.java uses
unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
: Compile failed; see the compiler error output for details.
         at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:933)


any ideas?

thanks
--
Hamish
http://www.dcs.shef.ac.uk/~hamish/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Marc Palmer Local

On 17 May 2007, at 13:50, Hamish Cunningham wrote:

> hi
>
> Graeme Rocher wrote:
>> http://svn.grails-plugins.codehaus.org/browse/~raw,r=75/grails- 
>> plugins/grails-staticresources/grails-StaticResources-0.3.zip
>
> thanks; I got it now. I can't get it to run though (grails 0.5,  
> java 1.5)
>
> I did: grails install-plugin on the URL above, which seemed to  
> work, but then when I ran run-app I got a compile exception. I  
> tried grails upgrade within the plugin directory and run-app again,  
> but then I got a conflict between two versions of a class:

The plugin is not for 0.5 yet.

Run grails clean and then upgrade on the plugin source, and rebuild.

Marc





---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

JamesPage
In reply to this post by hamishagain@dcs.shef.ac.uk
The simplest thing is to sometimes forget about the middle layer. Just put sqiuid in front of your application server. I am writing a cache plugin at the moment so that squid and or the browser will catch most static content.

At the moment I am optimizing a bunch badly written Web2.0 PHP sites running on apache. The performance uplift we are getting is about a factor of 10 and that is in front of apache. So there is massive saving on hardware... etc...

Marc if you are doing some stuff with Squid -- how are you handling views, etc,,, with cache purging... Are you purging the whole cache on any write to a table... Has anybody else got any ideas?

James

On 5/17/07, Hamish Cunningham <[hidden email]> wrote:
hi

Graeme Rocher wrote:
> http://svn.grails-plugins.codehaus.org/browse/~raw,r=75/grails-plugins/grails-staticresources/grails-StaticResources-0.3.zip

thanks; I got it now. I can't get it to run though (grails 0.5, java 1.5)

I did: grails install-plugin on the URL above, which seemed to work, but then
when I ran run-app I got a compile exception. I tried grails upgrade within
the plugin directory and run-app again, but then I got a conflict between two
versions of a class:

./plugins/StaticResources-0.3/plugins/core/grails-app/taglib/RenderTagLib.groovy
./plugins/core/grails-app/taglib/RenderTagLib.groovy]

so I removed the StaticResources...core directory, at which point my compile
exception came back, complaining about a .zip file (!):


     [javac] Compiling 1 source file to
/home/hamish/ext/sins/StaticResources- 0.3/web-app/WEB-INF/classes
error: error reading
/home/hamish/ext/sins/StaticResources-0.3/web-app/WEB-INF/classes/log4j.development.properties;
error in opening zip file
Note: /home/hamish/ext/sins/StaticResources- 0.3/src/java/NanoHTTPD.java uses
unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
: Compile failed; see the compiler error output for details.
         at org.apache.tools.ant.taskdefs.Javac.compile (Javac.java:933)


any ideas?

thanks
--
Hamish
http://www.dcs.shef.ac.uk/~hamish/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

Marc Palmer Local

On 17 May 2007, at 14:12, James Page wrote:

> The simplest thing is to sometimes forget about the middle layer.  
> Just put sqiuid in front of your application server. I am writing a  
> cache plugin at the moment so that squid and or the browser will  
> catch most static content.
>
> At the moment I am optimizing a bunch badly written Web2.0 PHP  
> sites running on apache. The performance uplift we are getting is  
> about a factor of 10 and that is in front of apache. So there is  
> massive saving on hardware... etc...
>
> Marc if you are doing some stuff with Squid -- how are you handling  
> views, etc,,, with cache purging... Are you purging the whole cache  
> on any write to a table... Has anybody else got any ideas?
>
Not even got there yet, still building the app. We need an app no  
matter what, even if its slow :)

I was hoping with squid we can just set a timeout. We will only be  
serving static content (images etc) not GSP rendered content so this  
is not such an issue. If I can get squid to cache all this stuff once  
an hour that will be fine :)

Marc



---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Serving static files with Grails

JamesPage
On 5/17/07, Marc Palmer <[hidden email]> wrote:

On 17 May 2007, at 14:12, James Page wrote:

> The simplest thing is to sometimes forget about the middle layer.
> Just put sqiuid in front of your application server. I am writing a
> cache plugin at the moment so that squid and or the browser will
> catch most static content.
>
> At the moment I am optimizing a bunch badly written Web2.0 PHP
> sites running on apache. The performance uplift we are getting is
> about a factor of 10 and that is in front of apache. So there is
> massive saving on hardware... etc...
>
> Marc if you are doing some stuff with Squid -- how are you handling
> views, etc,,, with cache purging... Are you purging the whole cache
> on any write to a table... Has anybody else got any ideas?
>
Not even got there yet, still building the app. We need an app no
matter what, even if its slow :)

I was hoping with squid we can just set a timeout. We will only be
serving static content (images etc) not GSP rendered content so this
is not such an issue. If I can get squid to cache all this stuff once
an hour that will be fine :)

Marc

Our cache plugin will take care of all that so you will not have to worry about that at all...

I have not started to write the GSP side yet... But when I do your advice would be great.... I think I will push out the static file side out first and then have GSP functionality as a second  version.

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email