{"id":28760,"date":"2015-10-22T12:31:41","date_gmt":"2015-10-22T07:01:41","guid":{"rendered":"https:\/\/2thenew.today\/blog\/?p=28760"},"modified":"2015-10-22T12:36:59","modified_gmt":"2015-10-22T07:06:59","slug":"generating-grails-static-resource-link-manually","status":"publish","type":"post","link":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/","title":{"rendered":"Generating Grails static resource link manually"},"content":{"rendered":"<p>In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary &#8216;src&#8217; class &#8211; following is a quick code that can help you getting the resources link\/URL (by using resources tag lib only). The good part is that it&#8217;s not a hard-coded URL, so it will follow all the standards\/settings configured around the Grails <a href=\"http:\/\/grails.org\/plugin\/resources\">resources-plugin<\/a>. <\/p>\n<p>[code]<br \/>\ndef grailsApplication<br \/>\nString getStaticResourceLink(String uri){<br \/>\n        if(uri){<br \/>\n            def resourceTagLib = grailsApplication.mainContext.getBean(&quot;org.grails.plugin.resource.ResourceTagLib&quot;)<br \/>\n            def rLinkResource = resourceTagLib ? resourceTagLib.resolveLinkUriToUriAndResource(uri: uri): null<br \/>\n            if(rLinkResource)<br \/>\n                uri = rLinkResource.uri<br \/>\n        }<br \/>\n        return uri<br \/>\n    }<br \/>\n[\/code]<\/p>\n<p>Usually, resources plugin automatically renders the URLs in an application. But this was a very special requirement where I was required to generate the link manually. Another condition was to follow all the resources-plugin&#8217;s settings because it does a lot of work before generating the (dynamic\/accurate\/relevant) links. So this worked very well &#8211; even for the CDN configurations.<br \/>\nThe only thing you need to take care is to pass the correct &#8220;uri&#8221; otherwise (if resource not found at the given location\/uri) you may get a broken link.<\/p>\n<p>I hope it will help someone. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary &#8216;src&#8217; class &#8211; following is a quick code that can help you getting the resources link\/URL (by using resources tag lib only). The good part is that it&#8217;s not a [&hellip;]<\/p>\n","protected":false},"author":606,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2,"footnotes":""},"categories":[7,1],"tags":[2648],"class_list":["post-28760","post","type-post","status-publish","format-standard","hentry","category-grails","category-technology","tag-grails-resources-plugin"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary &#039;src&#039; class - following is a quick code that can help you getting the resources link\/URL (by using resources tag lib only). The good part is that it&#039;s not a\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Salil Kumar\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Generating Grails static resource link manually | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary &#039;src&#039; class - following is a quick code that can help you getting the resources link\/URL (by using resources tag lib only). The good part is that it&#039;s not a\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Generating Grails static resource link manually | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary &#039;src&#039; class - following is a quick code that can help you getting the resources link\/URL (by using resources tag lib only). The good part is that it&#039;s not a\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/#article\",\"name\":\"Generating Grails static resource link manually | TO THE NEW Blog\",\"headline\":\"Generating Grails static resource link manually\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/salil-3\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2015-10-22T12:31:41+05:30\",\"dateModified\":\"2015-10-22T12:36:59+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/#webpage\"},\"articleSection\":\"Grails, Technology, grails-resources-plugin\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/#listItem\",\"name\":\"Generating Grails static resource link manually\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/#listItem\",\"position\":3,\"name\":\"Generating Grails static resource link manually\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/salil-3\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/salil-3\\\/\",\"name\":\"Salil Kumar\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/#authorImage\",\"url\":\"https:\\\/\\\/newersworld-sf-static.tothenew.net\\\/prod\\\/profilePicFolder\\\/487d6b33-0950-4f6b-b106-a51c27f3e8ca_salil.kumar@tothenew.com.jpg\",\"width\":96,\"height\":96,\"caption\":\"Salil Kumar\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/\",\"name\":\"Generating Grails static resource link manually | TO THE NEW Blog\",\"description\":\"In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary 'src' class - following is a quick code that can help you getting the resources link\\\/URL (by using resources tag lib only). The good part is that it's not a\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/generating-grails-static-resource-link-manually\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/salil-3\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/salil-3\\\/#author\"},\"datePublished\":\"2015-10-22T12:31:41+05:30\",\"dateModified\":\"2015-10-22T12:36:59+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Generating Grails static resource link manually | TO THE NEW Blog","description":"In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary 'src' class - following is a quick code that can help you getting the resources link\/URL (by using resources tag lib only). The good part is that it's not a","canonical_url":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/#article","name":"Generating Grails static resource link manually | TO THE NEW Blog","headline":"Generating Grails static resource link manually","author":{"@id":"https:\/\/2thenew.today\/blog\/author\/salil-3\/#author"},"publisher":{"@id":"https:\/\/2thenew.today\/blog\/#organization"},"datePublished":"2015-10-22T12:31:41+05:30","dateModified":"2015-10-22T12:36:59+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/#webpage"},"isPartOf":{"@id":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/#webpage"},"articleSection":"Grails, Technology, grails-resources-plugin"},{"@type":"BreadcrumbList","@id":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog#listItem","position":1,"name":"Home","item":"https:\/\/2thenew.today\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/2thenew.today\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/#listItem","name":"Generating Grails static resource link manually"},"previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/#listItem","position":3,"name":"Generating Grails static resource link manually","previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.today\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/2thenew.today\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/2thenew.today\/blog\/"},{"@type":"Person","@id":"https:\/\/2thenew.today\/blog\/author\/salil-3\/#author","url":"https:\/\/2thenew.today\/blog\/author\/salil-3\/","name":"Salil Kumar","image":{"@type":"ImageObject","@id":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/#authorImage","url":"https:\/\/newersworld-sf-static.tothenew.net\/prod\/profilePicFolder\/487d6b33-0950-4f6b-b106-a51c27f3e8ca_salil.kumar@tothenew.com.jpg","width":96,"height":96,"caption":"Salil Kumar"}},{"@type":"WebPage","@id":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/#webpage","url":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/","name":"Generating Grails static resource link manually | TO THE NEW Blog","description":"In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary 'src' class - following is a quick code that can help you getting the resources link\/URL (by using resources tag lib only). The good part is that it's not a","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/2thenew.today\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/#breadcrumblist"},"author":{"@id":"https:\/\/2thenew.today\/blog\/author\/salil-3\/#author"},"creator":{"@id":"https:\/\/2thenew.today\/blog\/author\/salil-3\/#author"},"datePublished":"2015-10-22T12:31:41+05:30","dateModified":"2015-10-22T12:36:59+05:30"},{"@type":"WebSite","@id":"https:\/\/2thenew.today\/blog\/#website","url":"https:\/\/2thenew.today\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/2thenew.today\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Generating Grails static resource link manually | TO THE NEW Blog","og:description":"In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary 'src' class - following is a quick code that can help you getting the resources link\/URL (by using resources tag lib only). The good part is that it's not a","og:url":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/","og:image":"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Generating Grails static resource link manually | TO THE NEW Blog","twitter:description":"In case you are using Grails resources plugin and at some point you need to generate the static resource link in some service or ordinary 'src' class - following is a quick code that can help you getting the resources link\/URL (by using resources tag lib only). The good part is that it's not a","twitter:image":"https:\/\/2thenew.today\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"28760","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"blog","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-30 06:39:03","updated":"2024-02-29 10:03:05","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.today\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.today\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tGenerating Grails static resource link manually\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/2thenew.today\/blog"},{"label":"Technology","link":"https:\/\/2thenew.today\/blog\/category\/technology\/"},{"label":"Generating Grails static resource link manually","link":"https:\/\/2thenew.today\/blog\/generating-grails-static-resource-link-manually\/"}],"_links":{"self":[{"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/posts\/28760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/users\/606"}],"replies":[{"embeddable":true,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/comments?post=28760"}],"version-history":[{"count":0,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/posts\/28760\/revisions"}],"wp:attachment":[{"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/media?parent=28760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/categories?post=28760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2thenew.today\/blog\/wp-json\/wp\/v2\/tags?post=28760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}