ember-cli / broccoli-asset-rev

Broccoli plugin to add fingerprint checksums and CDN URLs to your assets
MIT License
87 stars 84 forks source link

Add asset map to the bundle as a JS module, so that it can be accessed programmatically without extra network requests #141

Open lolmaus opened 3 years ago

lolmaus commented 3 years ago

Hi! Thanks for the infrastructural addon!

Problem

I need to access files over network. With the current implementation of broccoli-asset-map, I have the following options:

As you can see, all options are suboptimal.

I ended up using the first one, adding a random query param to bust the cache. This make this option tolerable.

Suggested solution

Making the asset map accessible as part of the JS bundle resolves the issue: we will be able to fetch fingerprinted assets without extra network requests, with cache busted when needed and only when needed.

Could be import { assetMap } from 'broccoli-asset-rev' or something.

Of course, this feature should be opt-in to avoid increasing bundle size for those who don't need it.

CC @simonihmig.

lolmaus commented 3 years ago

I've found this addon: https://github.com/adopted-ember-addons/ember-cli-ifa

It does what I'm asking for, but at the cost of increasing bundle size substantially. It has a service, an initializer, a helper, an util...

I just want to do this, without all the extra weight:

import { assetMap } from 'broccoli-asset-rev';

// e. g. in route model hook:
const url = '/' + assetMap.assets['api/posts/all.json'];
return fetch(url);