Hard-coded resource path vs $Resource global variable?
Clash 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?
lightning-components static-resources
add a comment |Â
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?
lightning-components static-resources
add a comment |Â
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?
lightning-components static-resources
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
lightning-components static-resources
edited 3 hours ago
Adrian Larsonâ¦
100k19106225
100k19106225
asked 4 hours ago
Caspar Harmer
12.2k21749
12.2k21749
add a comment |Â
add a comment |Â
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.
Nicely put. Looks like I'll be using the Global var next time :)
â Caspar Harmer
2 hours ago
add a comment |Â
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.
Nicely put. Looks like I'll be using the Global var next time :)
â Caspar Harmer
2 hours ago
add a comment |Â
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.
Nicely put. Looks like I'll be using the Global var next time :)
â Caspar Harmer
2 hours ago
add a comment |Â
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.
$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.
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password