ember-cli-ifa icon indicating copy to clipboard operation
ember-cli-ifa copied to clipboard

assetmap url when prepend is empty

Open sebastianhelbig opened this issue 7 years ago • 7 comments

fingerprint: {
      enabled: true
      fingerprintAssetMap: true,
      generateAssetMap: true,
      prepend: ''
}
rootUrl: '/',
ifa: {
      enabled: true,
      inline: false
}

If I open my app under a path which is not the root path, e.g. localhost:4200/de/intern/users fetching of the asset map file fails because it uses the empty prepend option and tries to fetch it relative the current path localhost:4200/de/intern/assets/assetMap-533afc92713400107780e8d5d67b0d89.json

I solved it by adding

  if ('/' !== assetMapFile.charAt(0)) {
    assetMapFile = `/${assetMapFile}`;
  }

to the initializer. But I am not sure if this will have any negative effects for other users?

sebastianhelbig avatar Jan 30 '18 16:01 sebastianhelbig

@sebastianhelbig why you have empty prepend in this case? It should be / if it is a root path, or something else if it's not root in your case.

Would be good to know your use-case in more detail, why prepend is '' for you?

RuslanZavacky avatar Jan 30 '18 16:01 RuslanZavacky

I use empty prepend, because I have the following problem.

I have image urls stored in models. These images get manually inserted in an image like component.

url: '/images/aabb'
…
this.$().append(`<img src="${model.url}">`);

With disabled fingerprintig this works perfectly. With enabled fingerprinting and non-empty prepend the prepend will be added additionally, so the url will be '//images/aabb', which does not load the image.

Btw: The default prepend is also '' according to https://ember-cli.com/user-guide/#fingerprinting-and-cdn-urls

sebastianhelbig avatar Feb 13 '18 18:02 sebastianhelbig

we're also having issues with this. the prepend option does not necessarily make sense. if IFA is disabled, its more than likely that whatever was prepended to the asset paths will still need to be there.

I think it would be better to simply make the path to the assetMap json file configurable.

Due to the changes removing baseUrl we're adding a rootUrl property to all components and controllers:

https://github.com/ember-cli/ember-cli/issues/6178

Having both the prepend configuration w/ ember-cli-ifa and the changes w/ the rootUrl in ember-cli are conflicting.

The workaround we are implementing is to add a imageRootUrl that will check if IFA is enabled or not to apply the rootUrl or not to avoid duplicating, ala //assets.

adamhong avatar Mar 07 '18 21:03 adamhong

Works in production but not in development with ifa disabled, in development the prepend value is always "/"

k-dauda avatar Mar 14 '18 20:03 k-dauda

@Turbo87 was this one of the issues that you fixed with your recent PR? 🤔

mansona avatar Oct 23 '19 13:10 mansona

no, I did not touch this part of the addon

Turbo87 avatar Oct 23 '19 13:10 Turbo87

Having the same issue. After looking at the initializer I believe the issue is due to properties on the AssetMap service are not being consistently set across environments. The initializer skips setting the prepend option if there is no asset-map (i.e. development environment) because it early returns here.

jbailey4 avatar Jun 11 '20 18:06 jbailey4