You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Simon B <si...@gmail.com> on 2014/06/09 13:20:32 UTC

javascript reference header item with async attribute

Hi, 

I'm using Wicket 6.15

What is the best way to set the async attribute when rendering a javascript
header item.

I would like to change :




to 



or even



I see that there is a flag for setting the defer attribute but could not
find anything for async.

Any suggestions?

Cheers
Simon

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/javascript-reference-header-item-with-async-attribute-tp4666155.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: javascript reference header item with async attribute

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

I don't like the number of constructors we have in the different impls of
CssHeaderItem and JavaScriptHeaderItem.
Recently I needed to set markup id to a CssHeaderItem to be able to replace
it with Ajax so I've added a new method [1] to CssHeaderItem: setId(String)
[2] that uses Fluent API pattern, i.e. returns "this".
Usage:  render(CssHeaderItem.forXyz(...).setId("someId"));

"async" is a new attribute added with HTML5 and is different than "defer"
I think we can do the same and add it without changing the current APIs,
i.e. adding more constructors/methods.
The usage would be: render(CssHeaderItem.forXyz(...).setAsync(true));

If you like the idea then please open a ticket at
https://issues.apache.org/jira/browse/WICKET

1. https://issues.apache.org/jira/browse/WICKET-5617
2.
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/head/CssHeaderItem.java#L80

Martin Grigorov
Wicket Training and Consulting


On Mon, Jun 9, 2014 at 4:45 PM, Simon B <si...@gmail.com> wrote:

> Hello Andrea,
>
> Thank you for replying.  In the end I subclassed
> JavaScriptUrlReferenceHeaderItem creating my own
> AsyncJavaScriptUrlReferenceHeaderItem class
>
> and overrode the
>
>  public void render(Response response);
>
> method, take as a reference the implemenation from
> JavaScriptUtils.writeJavaScriptUrl and JavaScriptUrlHeaderItem and simply
> adding a async attribute in one of the response.write method calls:
>
>
>
> Seems a bit of a brutish way just to add an async attribute.
>
> Is this something that could // should be added to a future release of
> wicket, does anyone have any opinion about it?
>
> Cheers
> Simon
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/javascript-reference-header-item-with-async-attribute-tp4666155p4666159.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: javascript reference header item with async attribute

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

I don't like the number of constructors we have in the different impls of
CssHeaderItem and JavaScriptHeaderItem.
Recently I needed to set markup id to a CssHeaderItem to be able to replace
it with Ajax so I've added a new method [1] to CssHeaderItem: setId(String)
[2] that uses Fluent API pattern, i.e. returns "this".
Usage:  render(CssHeaderItem.forXyz(...).setId("someId"));

"async" is a new attribute added with HTML5 and is different than "defer"
I think we can do the same and add it without changing the current APIs,
i.e. adding more constructors/methods.
The usage would be: render(CssHeaderItem.forXyz(...).setAsync(true));

If you like the idea then please open a ticket at
https://issues.apache.org/jira/browse/WICKET

1. https://issues.apache.org/jira/browse/WICKET-5617
2.
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/head/CssHeaderItem.java#L80

Martin Grigorov
Wicket Training and Consulting


On Mon, Jun 9, 2014 at 4:45 PM, Simon B <si...@gmail.com> wrote:

> Hello Andrea,
>
> Thank you for replying.  In the end I subclassed
> JavaScriptUrlReferenceHeaderItem creating my own
> AsyncJavaScriptUrlReferenceHeaderItem class
>
> and overrode the
>
>  public void render(Response response);
>
> method, take as a reference the implemenation from
> JavaScriptUtils.writeJavaScriptUrl and JavaScriptUrlHeaderItem and simply
> adding a async attribute in one of the response.write method calls:
>
>
>
> Seems a bit of a brutish way just to add an async attribute.
>
> Is this something that could // should be added to a future release of
> wicket, does anyone have any opinion about it?
>
> Cheers
> Simon
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/javascript-reference-header-item-with-async-attribute-tp4666155p4666159.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: javascript reference header item with async attribute

Posted by Simon B <si...@gmail.com>.
Hello Andrea, 

Thank you for replying.  In the end I subclassed
JavaScriptUrlReferenceHeaderItem creating my own
AsyncJavaScriptUrlReferenceHeaderItem class

and overrode the 

 public void render(Response response); 

method, take as a reference the implemenation from
JavaScriptUtils.writeJavaScriptUrl and JavaScriptUrlHeaderItem and simply
adding a async attribute in one of the response.write method calls: 



Seems a bit of a brutish way just to add an async attribute. 

Is this something that could // should be added to a future release of
wicket, does anyone have any opinion about it?

Cheers
Simon

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/javascript-reference-header-item-with-async-attribute-tp4666155p4666159.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: javascript reference header item with async attribute

Posted by Andrea Del Bene <an...@gmail.com>.
AFAIK you can use attribute 'defer' with JavaScriptHeaderItem. I'm not sure
that exists a standard way to add other attribute to <script> tag.


On Mon, Jun 9, 2014 at 1:20 PM, Simon B <si...@gmail.com> wrote:

> Hi,
>
> I'm using Wicket 6.15
>
> What is the best way to set the async attribute when rendering a javascript
> header item.
>
> I would like to change :
>
>
>
>
> to
>
>
>
> or even
>
>
>
> I see that there is a flag for setting the defer attribute but could not
> find anything for async.
>
> Any suggestions?
>
> Cheers
> Simon
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/javascript-reference-header-item-with-async-attribute-tp4666155.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>