The problem: broccoli-asset-rev works perfectly for paths which are simple strings but does not match for dynamically generated strings like assets/img/${this.baseSrc}-1280.jpg.
The solution(s): There seems to be quite a few possible approaches to solving this, like addons like Ember CLI IFA which use the postBuild hook to insert a serialized asset map into the html document, or a similar approach @ryanto shared inserting the serialized json into the vendor.js instead.
The issue: Unfortuntately I've been unable to get any of them to work with Prember. Initially, I used ember-cli-ifa as the basis for a solution which would also work with Fastboot—by using dedicated initializers to extract the meta content via document in browser and via JSDOM with Fastboot.
You can see the Fastboot initializer here but unfortunately despite trying to block the rendering with fastboot.deferRendering() the first initial render in Fastboot still seems to miss the fingerprinting.
Rendering with Prember the fastboot.request.host is correct as localhost:7784, but the fastboot.request.protocol seems absent. Worse, it seems like even hardcoding the protocol the initializer is running before the postBuild hook has finished—because the error message relates to the pre-replaced content ie
Unexpected token _ in JSON at position 0
Due to the fact that I'm also using Broccoli Static Site JSON for the CMS and it seems like there is some ongoing work on the integration with Prember I decided that the injecting json into vendor.js approach might be simpler to achieve my aims.
Unfortunately that seems to bring a different set of problems which I think are more due to the synchronisation necessary between addons.
I notice you have done a lot of work on trying to disentangle broccoli-asset-rev from Fasboot but so far I have not been able to order the addons correctly to achieve the goals I want.
I have 3 in-repo-addons
- json-api (which uses
treeForPublic hook to merge content)
- ember-cli-asset-map (which uses
postBuild to inject the asset map json into vendor.js)
- prember-urls-crawler (which generates the urls and uses the
urlsForPrember hook)
My aim is to run them so that ember-cli-asset-map runs before prember-urls-crawler so that the fingerprinted URLs are available in Fastboot/Prember.
So far I haven't been able to find a combination of ordering which results in that. No matter what I use in the package.json ie using
{
"name": "prember-urls-crawler",
"keywords": [
"ember-addon",
"prember-plugin"
],
"ember-addon": {
"after": "ember-cli-asset-map"
}
}
If I output a message from the postBuild hook in the ember-cli-asset-map addon it always comes after the output of the Prember generation, like this:
merging via json-api
pre-render / 200 OK
asset map written to vendor.js
Have I missed something or is this a bug with Prember and the way it interacts with other addons?
Many thanks.
The problem:
broccoli-asset-revworks perfectly for paths which are simple strings but does not match for dynamically generated strings likeassets/img/${this.baseSrc}-1280.jpg.The solution(s): There seems to be quite a few possible approaches to solving this, like addons like Ember CLI IFA which use the
postBuildhook to insert a serialized asset map into the html document, or a similar approach @ryanto shared inserting the serialized json into the vendor.js instead.The issue: Unfortuntately I've been unable to get any of them to work with Prember. Initially, I used
ember-cli-ifaas the basis for a solution which would also work with Fastboot—by using dedicated initializers to extract the meta content viadocumentin browser and viaJSDOMwith Fastboot.You can see the Fastboot initializer here but unfortunately despite trying to block the rendering with
fastboot.deferRendering()the first initial render in Fastboot still seems to miss the fingerprinting.Rendering with Prember the
fastboot.request.hostis correct as localhost:7784, but thefastboot.request.protocolseems absent. Worse, it seems like even hardcoding the protocol the initializer is running before thepostBuildhook has finished—because the error message relates to the pre-replaced content ieUnexpected token _ in JSON at position 0Due to the fact that I'm also using Broccoli Static Site JSON for the CMS and it seems like there is some ongoing work on the integration with Prember I decided that the injecting json into
vendor.jsapproach might be simpler to achieve my aims.Unfortunately that seems to bring a different set of problems which I think are more due to the synchronisation necessary between addons.
I notice you have done a lot of work on trying to disentangle
broccoli-asset-revfrom Fasboot but so far I have not been able to order the addons correctly to achieve the goals I want.I have 3 in-repo-addons
treeForPublichook to merge content)postBuildto inject the asset map json intovendor.js)urlsForPremberhook)My aim is to run them so that
ember-cli-asset-mapruns beforeprember-urls-crawlerso that the fingerprinted URLs are available in Fastboot/Prember.So far I haven't been able to find a combination of ordering which results in that. No matter what I use in the
package.jsonie using{ "name": "prember-urls-crawler", "keywords": [ "ember-addon", "prember-plugin" ], "ember-addon": { "after": "ember-cli-asset-map" } }If I output a message from the
postBuildhook in theember-cli-asset-mapaddon it always comes after the output of the Prember generation, like this:Have I missed something or is this a bug with Prember and the way it interacts with other addons?
Many thanks.