Hard-coded resource path vs $Resource global variable?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I've never been able to work out which format is better or if there any differences between these lightning resource access formats:



<img src="!$Resource.your_pic"/>


And



<img src="/resource/your_pic"/>


Most of the time the documentation recommends the former format, but the latter is sometimes used, seems to work fine and looks a lot cleaner.



Can anyone shed some illumination on this?










share|improve this question





























    up vote
    2
    down vote

    favorite












    I've never been able to work out which format is better or if there any differences between these lightning resource access formats:



    <img src="!$Resource.your_pic"/>


    And



    <img src="/resource/your_pic"/>


    Most of the time the documentation recommends the former format, but the latter is sometimes used, seems to work fine and looks a lot cleaner.



    Can anyone shed some illumination on this?










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I've never been able to work out which format is better or if there any differences between these lightning resource access formats:



      <img src="!$Resource.your_pic"/>


      And



      <img src="/resource/your_pic"/>


      Most of the time the documentation recommends the former format, but the latter is sometimes used, seems to work fine and looks a lot cleaner.



      Can anyone shed some illumination on this?










      share|improve this question















      I've never been able to work out which format is better or if there any differences between these lightning resource access formats:



      <img src="!$Resource.your_pic"/>


      And



      <img src="/resource/your_pic"/>


      Most of the time the documentation recommends the former format, but the latter is sometimes used, seems to work fine and looks a lot cleaner.



      Can anyone shed some illumination on this?







      lightning-components static-resources






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 3 hours ago









      Adrian Larson♦

      100k19106225




      100k19106225










      asked 4 hours ago









      Caspar Harmer

      12.2k21749




      12.2k21749




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          $Resource has two benefits: cache busting and automatic path resolution. By cache busting, we're referring to the fact that the /resource/name has a very long expiry time, and so you'll find it harder to load changes to the file without clearing your browser's cache. $Resource solves this by putting a timestamp from the resource into the url, something like /resource/123893218321/name. This allows the long expiry to work for each version of the file.



          By automatic path resolution, we're primarily concerned about communities and portals. These can have prefixes, which ultimately alter the path you need to use. For example, in a community, it might be /s/resource/name instead of just /resource/name, so the user would get a 404 (e.g. a blank image, error message, something else). As a further benefit, if salesforce.com decides to alter how these files are accessed, developers that have been using $Resource will already be prepared for those changes, while those using /resource/ may have to update their code.



          This $Resource variable, by the way, works in both Lightning and Visualforce, and should always be used. Some documentation may choose not to do this, but it definitely should not be considered a best practice.






          share|improve this answer




















          • Nicely put. Looks like I'll be using the Global var next time :)
            – Caspar Harmer
            2 hours ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f233191%2fhard-coded-resource-path-vs-resource-global-variable%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          $Resource has two benefits: cache busting and automatic path resolution. By cache busting, we're referring to the fact that the /resource/name has a very long expiry time, and so you'll find it harder to load changes to the file without clearing your browser's cache. $Resource solves this by putting a timestamp from the resource into the url, something like /resource/123893218321/name. This allows the long expiry to work for each version of the file.



          By automatic path resolution, we're primarily concerned about communities and portals. These can have prefixes, which ultimately alter the path you need to use. For example, in a community, it might be /s/resource/name instead of just /resource/name, so the user would get a 404 (e.g. a blank image, error message, something else). As a further benefit, if salesforce.com decides to alter how these files are accessed, developers that have been using $Resource will already be prepared for those changes, while those using /resource/ may have to update their code.



          This $Resource variable, by the way, works in both Lightning and Visualforce, and should always be used. Some documentation may choose not to do this, but it definitely should not be considered a best practice.






          share|improve this answer




















          • Nicely put. Looks like I'll be using the Global var next time :)
            – Caspar Harmer
            2 hours ago














          up vote
          4
          down vote



          accepted










          $Resource has two benefits: cache busting and automatic path resolution. By cache busting, we're referring to the fact that the /resource/name has a very long expiry time, and so you'll find it harder to load changes to the file without clearing your browser's cache. $Resource solves this by putting a timestamp from the resource into the url, something like /resource/123893218321/name. This allows the long expiry to work for each version of the file.



          By automatic path resolution, we're primarily concerned about communities and portals. These can have prefixes, which ultimately alter the path you need to use. For example, in a community, it might be /s/resource/name instead of just /resource/name, so the user would get a 404 (e.g. a blank image, error message, something else). As a further benefit, if salesforce.com decides to alter how these files are accessed, developers that have been using $Resource will already be prepared for those changes, while those using /resource/ may have to update their code.



          This $Resource variable, by the way, works in both Lightning and Visualforce, and should always be used. Some documentation may choose not to do this, but it definitely should not be considered a best practice.






          share|improve this answer




















          • Nicely put. Looks like I'll be using the Global var next time :)
            – Caspar Harmer
            2 hours ago












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          $Resource has two benefits: cache busting and automatic path resolution. By cache busting, we're referring to the fact that the /resource/name has a very long expiry time, and so you'll find it harder to load changes to the file without clearing your browser's cache. $Resource solves this by putting a timestamp from the resource into the url, something like /resource/123893218321/name. This allows the long expiry to work for each version of the file.



          By automatic path resolution, we're primarily concerned about communities and portals. These can have prefixes, which ultimately alter the path you need to use. For example, in a community, it might be /s/resource/name instead of just /resource/name, so the user would get a 404 (e.g. a blank image, error message, something else). As a further benefit, if salesforce.com decides to alter how these files are accessed, developers that have been using $Resource will already be prepared for those changes, while those using /resource/ may have to update their code.



          This $Resource variable, by the way, works in both Lightning and Visualforce, and should always be used. Some documentation may choose not to do this, but it definitely should not be considered a best practice.






          share|improve this answer












          $Resource has two benefits: cache busting and automatic path resolution. By cache busting, we're referring to the fact that the /resource/name has a very long expiry time, and so you'll find it harder to load changes to the file without clearing your browser's cache. $Resource solves this by putting a timestamp from the resource into the url, something like /resource/123893218321/name. This allows the long expiry to work for each version of the file.



          By automatic path resolution, we're primarily concerned about communities and portals. These can have prefixes, which ultimately alter the path you need to use. For example, in a community, it might be /s/resource/name instead of just /resource/name, so the user would get a 404 (e.g. a blank image, error message, something else). As a further benefit, if salesforce.com decides to alter how these files are accessed, developers that have been using $Resource will already be prepared for those changes, while those using /resource/ may have to update their code.



          This $Resource variable, by the way, works in both Lightning and Visualforce, and should always be used. Some documentation may choose not to do this, but it definitely should not be considered a best practice.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 hours ago









          sfdcfox

          228k10176390




          228k10176390











          • Nicely put. Looks like I'll be using the Global var next time :)
            – Caspar Harmer
            2 hours ago
















          • Nicely put. Looks like I'll be using the Global var next time :)
            – Caspar Harmer
            2 hours ago















          Nicely put. Looks like I'll be using the Global var next time :)
          – Caspar Harmer
          2 hours ago




          Nicely put. Looks like I'll be using the Global var next time :)
          – Caspar Harmer
          2 hours ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f233191%2fhard-coded-resource-path-vs-resource-global-variable%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery