{"id":3991,"date":"2012-01-11T16:45:20","date_gmt":"2012-01-12T00:45:20","guid":{"rendered":"http:\/\/blog.mozilla.org\/addons\/?p=3991"},"modified":"2012-01-11T16:45:20","modified_gmt":"2012-01-12T00:45:20","slug":"sdk-1-4-known-issue-with-hard-coding-resource-uris","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/","title":{"rendered":"SDK 1.4: known issue with hard-coding resource URIs"},"content":{"rendered":"<p>The Jetpack project released Addon SDK version 1.4 yesterday; this release is likely the most significant release of the SDK since 1.0 in June, and includes <a href=\"http:\/\/blog.mozilla.org\/addons\/2012\/01\/10\/announcing-add-on-sdk-1-4\/\" target=\"_blank\">a number of improvements<\/a>. One of the improvements was a change to simplify the internal file &#038; folder structure of the xpi packages the SDK creates. This work was tracked in <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=660629\" target=\"_blank\">bug 660629<\/a>.<\/p>\n<p>One side-effect of this change is that the resource urls for files in the data folder of an add-on have changed. If you have created an add-on and for some reason hard-coded a resource url into your code, you will need to change your code in order for your add-on to work when packaged with SDK version 1.4.<br \/>\n<!--break--><br \/>\nWhile the release notes <a href=\"https:\/\/wiki.mozilla.org\/Labs\/Jetpack\/Release_Notes\/1.4#Known_Issues\" target=\"_blank\">go into this issue in detail<\/a>, I would like to highlight here the two main examples we are seeing in the wild of hard coded resource uris, with strategies for working around each.<\/p>\n<h3>1. Hard coded resource uris in main.js<\/h3>\n<p>Addon authors occasionally reference html and javascript files in the addon&#8217;s data directory directly via a hard-coded string:<\/p>\n<pre lang=\"js\">var myPanel = require(\"panel\").Panel({\r\n  contentURL: \"resource:\/\/jid1-294x0ji6mesjag-at-jetpack-example-data\/my-file.html\",\r\n  contentScriptFile: \"resource:\/\/jid1-294x0ji6mesjag-at-jetpack-example-data\/my-script.js\"\r\n});<\/pre>\n<p>You should always use the method self.data.url instead:<\/p>\n<pre lang=\"js\">var data = require(\"self\").data;\r\nvar myPanel = require(\"panel\").Panel({\r\n  contentURL: data.url(\"my-file.html\"),\r\n  contentScriptFile: data.url(\"my-script.js\")\r\n});<\/pre>\n<h3>2. Hard coded resource uris in html or css files inside the data directory.<\/h3>\n<p>Referencing a css or image file from an html or css file in the addon&#8217;s data directory does not require the entire resource uri path because these resources can be referenced with relative paths. Instead of doing this:<\/p>\n<pre lang=\"html\">\r\n<html>\r\n  <body>\r\n    <img decoding=\"async\" src=\"resource:\/\/jid1-294x0ji6mesjag-at-jetpack-example-data\/my-file.png\"\/>\r\n  <\/body>\r\n<\/html>\r\n<\/pre>\n<p>&#8230;all you need to do is this:<\/p>\n<pre lang=\"html\">\r\n<html>\r\n  <body>\r\n    <img decoding=\"async\" src=\"my-file.png\"\/>\r\n  <\/body>\r\n<\/html>\r\n<\/pre>\n<p>If you have created an SDK-based addon and have included some hard-coded resource uris in your code, you will only need to make changes to address this issue if you re-package your addon with 1.4. As we are not re-packing addons on AMO automatically for this release, there is no immediate need to update your code. <\/p>\n<p>It is possible 6 weeks from now that we will re-pack all addons to use SDK 1.5, and at this point any remaining addons using hard-coded resource uris will stop working. To mitigate this we are working with the AMO team to identify all affected addons and contact addon authors directly to encourage them to update and use the best practices I demonstrated above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Jetpack project released Addon SDK version 1.4 yesterday; this release is likely the most significant release of the SDK since 1.0 in June, and includes a number of improvements. &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/\">Read more<\/a><\/p>\n","protected":false},"author":316,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[388,588,227,742],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SDK 1.4: known issue with hard-coding resource URIs  - Mozilla Add-ons Community Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeff Griffiths\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/\",\"url\":\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/\",\"name\":\"SDK 1.4: known issue with hard-coding resource URIs - Mozilla Add-ons Community Blog\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#primaryimage\"},\"thumbnailUrl\":\"resource:\/\/jid1-294x0ji6mesjag-at-jetpack-example-data\/my-file.png\",\"datePublished\":\"2012-01-12T00:45:20+00:00\",\"dateModified\":\"2012-01-12T00:45:20+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/e2f4c71eb45392ea29162432c3f1d433\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#primaryimage\",\"url\":\"resource:\/\/jid1-294x0ji6mesjag-at-jetpack-example-data\/my-file.png\",\"contentUrl\":\"resource:\/\/jid1-294x0ji6mesjag-at-jetpack-example-data\/my-file.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/addons\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SDK 1.4: known issue with hard-coding resource URIs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#website\",\"url\":\"https:\/\/blog.mozilla.org\/addons\/\",\"name\":\"Mozilla Add-ons Community Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.mozilla.org\/addons\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/e2f4c71eb45392ea29162432c3f1d433\",\"name\":\"Jeff Griffiths\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b07ae75dd1a5414bf30d7f773ccfc894?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b07ae75dd1a5414bf30d7f773ccfc894?s=96&d=mm&r=g\",\"caption\":\"Jeff Griffiths\"},\"description\":\"Jeff is Product Manager for the Firefox Developer Tools and occasional Open Web hacker, based in Vancouver, BC.\",\"sameAs\":[\"http:\/\/canuckistani.ca\/\",\"https:\/\/x.com\/canuckistani\"],\"url\":\"https:\/\/blog.mozilla.org\/addons\/author\/jgriffithsmozilla-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SDK 1.4: known issue with hard-coding resource URIs  - Mozilla Add-ons Community Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/","twitter_misc":{"Written by":"Jeff Griffiths","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/","url":"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/","name":"SDK 1.4: known issue with hard-coding resource URIs - Mozilla Add-ons Community Blog","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/addons\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#primaryimage"},"image":{"@id":"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#primaryimage"},"thumbnailUrl":"resource:\/\/jid1-294x0ji6mesjag-at-jetpack-example-data\/my-file.png","datePublished":"2012-01-12T00:45:20+00:00","dateModified":"2012-01-12T00:45:20+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/e2f4c71eb45392ea29162432c3f1d433"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#primaryimage","url":"resource:\/\/jid1-294x0ji6mesjag-at-jetpack-example-data\/my-file.png","contentUrl":"resource:\/\/jid1-294x0ji6mesjag-at-jetpack-example-data\/my-file.png"},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/addons\/2012\/01\/11\/sdk-1-4-known-issue-with-hard-coding-resource-uris\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/addons\/"},{"@type":"ListItem","position":2,"name":"SDK 1.4: known issue with hard-coding resource URIs"}]},{"@type":"WebSite","@id":"https:\/\/blog.mozilla.org\/addons\/#website","url":"https:\/\/blog.mozilla.org\/addons\/","name":"Mozilla Add-ons Community Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.mozilla.org\/addons\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/e2f4c71eb45392ea29162432c3f1d433","name":"Jeff Griffiths","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/addons\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b07ae75dd1a5414bf30d7f773ccfc894?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b07ae75dd1a5414bf30d7f773ccfc894?s=96&d=mm&r=g","caption":"Jeff Griffiths"},"description":"Jeff is Product Manager for the Firefox Developer Tools and occasional Open Web hacker, based in Vancouver, BC.","sameAs":["http:\/\/canuckistani.ca\/","https:\/\/x.com\/canuckistani"],"url":"https:\/\/blog.mozilla.org\/addons\/author\/jgriffithsmozilla-com\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/posts\/3991"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/users\/316"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/comments?post=3991"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/posts\/3991\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/media?parent=3991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/categories?post=3991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/addons\/wp-json\/wp\/v2\/tags?post=3991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}