You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Juan Germán Castañeda Echevarria <ju...@ciencias.unam.mx> on 2012/04/12 00:05:20 UTC

HTTP header modification for Cache-Control in Browser

Hi everyone,

I want to be able to disable the browsers cache in some
pages programmatically by adding the necessary HTTP headers to the
response. I found the following recipe where it is shown how to do
something similar with an annotation and a MarkupRenderFilter
http://tapestry.apache.org/meta-programming-page-content.html.

Is that the best, only and/or current way to do it? Just want to know
before actually writing it.

Hopefully someone has already tackled that problem and can share his
experience and maybe it could be added to Tapestry since I've seen that it
is a recurring topic on this list.

Thanks in advance

-- 
Juan Germán Castañeda Echevarría

Re: HTTP header modification for Cache-Control in Browser

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 11 Apr 2012 20:03:46 -0300, Juan Germán Castañeda Echevarria  
<ju...@ciencias.unam.mx> wrote:

> Yes, I think that too. Though it may look like that because of all the
> configuration they are doing for mapping the annotation to use
> MetaDataLocator.

That would be needed in order to control the addition or not of HTTP  
headers in a page-by-page basis, driven by an annotation.

> So, I will need the annotation for pages with the special headers and a
> ComponentRequestFilter, right?

Yep! Or a MarkupWriterFilter. Both can be used in this case, but  
MarkupWriterFilter will be more appropriate if you want to change the HTML  
DOM before sending to the browser.

> I also thought about adding it to the layout but I read that it sometimes
> doesn't work with Internet Explorer but you made me think, what if I want
> both the header and the meta tag? Could it be done using the
> MarkupRendererFilter?

Yes.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: HTTP header modification for Cache-Control in Browser

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 11 Apr 2012 19:05:20 -0300, Juan Germán Castañeda Echevarria  
<ju...@ciencias.unam.mx> wrote:

> Hi everyone,

Hi!

> I want to be able to disable the browsers cache in some
> pages programmatically by adding the necessary HTTP headers to the
> response. I found the following recipe where it is shown how to do
> something similar with an annotation and a MarkupRenderFilter
> http://tapestry.apache.org/meta-programming-page-content.html.
>
> Is that the best, only and/or current way to do it? Just want to know
> before actually writing it.

Not the only one. For setting HTTP headers only, I think that approach is  
a little overkill. You could implement a ComponentRequestFilter, @Inject  
the Response object in it and that and contribute the filter to the  
ComponentRequestHandler service.

I've started writing the answer thinking you were asking about adding meta  
tags, not HTTP headers. I don't want to waste what I've wrote, so here it  
goes. :P

If you have a single layout component used in all pages, you can use  
afterRender(MarkupWriter writer) and add the meta tags through through  
Tapestry DOM rewriting a.k.a. get the Document from the writer parameter  
and and some elements. If you don't have a single layout component, you  
can create a mixin that does the above and apply it to the layout  
components. Or you could write a ComponentClassTransformWorker that  
applies this mixin to all pages.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org