You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Eugene Zhulkov <ez...@gmail.com> on 2011/10/31 14:48:04 UTC

Insert Stylesheet to the Head top

Dear community!
I'm facing a trouble that I can't solve. But I think it's solvable :)
So I need to insert css stylesheet link to the top of the HEAD tag. Even
before Tapestry resources. 
I use @Import and Stacks to collect all needed resources for every page but
they are inserted by tapestry right after its css and js like this:




but I really need this:




Can I do this?

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4952484.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Insert Stylesheet to the Head top

Posted by Peter Stavrinides <P....@albourne.com>.
Great explanation Robert!

Thanks,
Peter
----- Original Message -----
From: "Eugene Zhulkov" <ez...@gmail.com>
To: users@tapestry.apache.org
Sent: Wednesday, 2 November, 2011 14:30:19 GMT +02:00 Athens, Bucharest, Istanbul
Subject: Re: Insert Stylesheet to the Head top

It works! Thank you all very much!

Code:



Overall processing time for main page of http://kindershopping.ru hasn't
changed:
before - min 149ms, mean 165ms, max 195ms
after - min 144ms, mean 163ms, max 365ms
 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4957961.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


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


Re: Insert Stylesheet to the Head top

Posted by Eugene Zhulkov <ez...@gmail.com>.
It works! Thank you all very much!

Code:



Overall processing time for main page of http://kindershopping.ru hasn't
changed:
before - min 149ms, mean 165ms, max 195ms
after - min 144ms, mean 163ms, max 365ms
 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4957961.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Insert Stylesheet to the Head top

Posted by Robert Zeigler <ro...@roxanemy.com>.
Remember,it's a pipeline that works like:

filter a -> filter b -> filter c -> final filter
and then the flow returns /back up/ the chain of filters
filter c -> filter b -> filter a.

The filter that handles placing the resources into the document is "DocumentLinker". It's added fairly early in the chain. It sets up some environment variables, then passes control down the chain. It adds the stylesheets to the document when control returns to the filter. The idea is that all of the component rendering, etc. adds to a growing list of assets that DocumentLinker needs to place into the document, and only when all of that rendering is finished are they actually added to the document.  So by specifying after:*, you have:

filter a -> document linker (setup environment) -> ... -> your filter
and then
your filter -> ... -> document linker (add resources) -> filter a

So what you really want is not to be after:*, but to be before:DocumentLinker, and then it would work like:

filter a -> your filter -> document linker (setup environment) -> ... 
... -> document linker (add various stylesheets -> your filter (add your custom css file here) -> filter a

Ie, contribute it before:DocumentLinker, and then your filter code would be something like:

public void renderMarkup(MarkupWriter writer, MarkupRenderer delegate) {
  //pass control through to document linker, etc.
  delegate.renderMarkup(writer);
  //now add your custom stylesheet.
  writer.getDocument()...
}

HTH,

Robert

On Nov 2, 2011, at 11/26:40 AM , Eugene Zhulkov wrote:

> I used "after:*" parameter so filter is called last in the chain of filters
> according to debugger's info.
> Also I tried to override last filter - DefaultValidationDecorator, with no
> results.
> 
> It seems tapestry resources are inserted after these filters. Outside
> MarkupRendererFilter routines 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4957882.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: Insert Stylesheet to the Head top

Posted by Eugene Zhulkov <ez...@gmail.com>.
I used "after:*" parameter so filter is called last in the chain of filters
according to debugger's info.
Also I tried to override last filter - DefaultValidationDecorator, with no
results.

It seems tapestry resources are inserted after these filters. Outside
MarkupRendererFilter routines 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4957882.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Insert Stylesheet to the Head top

Posted by Barry Books <tr...@gmail.com>.
My first guess would be you need to add an order to configuration.add
to make sure you run last (or at least after tapestry does it's thing)

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


Re: Insert Stylesheet to the Head top

Posted by Eugene Zhulkov <ez...@gmail.com>.
I've tried this code:



So as you can see I've added new filter which inserts <link> element after
html/head element. It works fine - this link appears in the resulting page.
But system resources (css and js) are being processed later by tapestry and
inserted before my resources... 

Any ideas?

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4957823.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Insert Stylesheet to the Head top

Posted by Eugene Zhulkov <ez...@gmail.com>.
Thank you for reply,

I'll try it but think it will drastically increase overall processing
time...  

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4955357.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Insert Stylesheet to the Head top

Posted by trsvax <tr...@gmail.com>.
You should be able to do this with a MarkupRendererFilter

Here is an example of one that puts code after the body tag

https://github.com/trsvax/tapestry-facebook/blob/master/src/main/java/com/trsvax/tapestry/facebook/services/FBModule.java



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4955340.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Insert Stylesheet to the Head top

Posted by Eugene Zhulkov <ez...@gmail.com>.
Sure I will :)

I'll try to do this tomorrow

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4955381.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Insert Stylesheet to the Head top

Posted by Eugene Zhulkov <ez...@gmail.com>.
Hello all,
I'm answering via cell phone so it might be some typos :)
The real reason i need one css file be included in the very beggining is our analytics system that gothers client's access attempts. This css file has zero file size and processed With special servlet. 

It's not possible to put css on the top of tml's layout since tapestry inserts its own resources first during rendering putting my resources second. 
I tried stack approach but with no results - seems its hardcoded in tapestry to put sys resources first :(

Отправлено с iPhone

31.10.2011, в 21:14, "Martin Strand-4 [via Tapestry]"<ml...@n5.nabble.com> написал(а):

> On Mon, 31 Oct 2011 18:58:31 +0100, Thiago H. de Paula Figueiredo <[hidden email]> wrote: 
> 
> > On Mon, 31 Oct 2011 11:48:04 -0200, Eugene Zhulkov <[hidden email]> 
> > wrote: 
> > 
> >> Dear community! 
> > 
> > Hi! 
> > 
> >> I'm facing a trouble that I can't solve. But I think it's solvable :) 
> >> So I need to insert css stylesheet link to the top of the HEAD tag. Even 
> >> before Tapestry resources. 
> > 
> > Why? I've never read about needing to add CSS files before JavaScript ones.
> 
> One reason is to make sure the CSS downloads start before any scripts soak up the browser's max connections. Loading CSS fast makes the app feel responsive. 
> Maxing out browser connections is however not a real problem since Tapestry can combine scripts to a single one. 
> 
> Also, some polyfill scripts (such as selectivizr) require stylesheets to be included first. 
> IMO it would make sense for Tapestry to put CSS first by default. 
> 
> 
> > Supposing you need to do this in all pages, one way of doing that is 
> > writing a mixin that users MarkupWriter to move the <style> element to 
> > where you want and apply this mixin to all pages. Another is to add your 
> > .css file directly in your Layout component template. 
> 
> --------------------------------------------------------------------- 
> To unsubscribe, e-mail: [hidden email] 
> For additional commands, e-mail: [hidden email] 
> 
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4953125.html
> To unsubscribe from Insert Stylesheet to the Head top, click here.


--
View this message in context: http://tapestry.1045711.n5.nabble.com/Insert-Stylesheet-to-the-Head-top-tp4952484p4953261.html
Sent from the Tapestry - User mailing list archive at Nabble.com.