I normally use the GWT ClientBundle for managing my images within my application like this
@Source("icons/info.png")
ImageResource info();
No I want to switch to .svg graphics but I didn't find a way to use svg in a ClientBundle like SVGResource or something. I know that svg is supported in GWT and there are possibilities to insert those graphics inside GWT, but I would like to use the advantages of the ClientBundle + the advantages of svg. Has anybody already solved this problem?
ImageResourceis for raster images that the GWT compiler could optimize in one way or another, and you can query for their size.For vector images like SVG, you can simply use a
DataResourcewith a@MimeType("image/svg+xml")annotation.Note that you cannot use a
@spritein aCssResourcethen, but you can get the resource's URL to use in, e.g., abackground-imageusing@url.You cannot pass the resource to an
Imagewidget either, but then you can just pass itsgetSafeUri().If you want the SVG content instead of using it as an image URL, then you can use a
TextResource. You'll have to pass it assetInnerHTMLto an element orsetHTMLto a widget to get it parsed by the browser.