Skip to content

Commit

Permalink
✨ Add option to disable cache buster for PreloadAsset
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Aug 14, 2020
1 parent 31310ae commit b9d7b75
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Carbon:
Default:
Package: SitePackage
CacheBuster: true
DisableCacheBusterForPreloadAsset: true
ConditionPrototype: null
Path:
Inline:
Expand Down
9 changes: 8 additions & 1 deletion Resources/Private/Fusion/External/Collection.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ prototype(Carbon.IncludeAssets:Collection) < prototype(Neos.Fusion:Component) {
collection = ${[]}
assetPackage = null
cacheBuster = ${Configuration.setting('Carbon.IncludeAssets.Default.CacheBuster')}
disableCacheBusterForPreloadAsset = ${Configuration.setting('Carbon.IncludeAssets.Default.DisableCacheBusterForPreloadAsset')}
paths = ${Configuration.setting('Carbon.IncludeAssets.Default.Path')}

renderer = afx`
<Neos.Fusion:Collection @if.render={props.assetPackage} collection={props.collection} @children='itemRenderer'>
<Carbon.IncludeAssets:File file={item} assetPackage={props.assetPackage} cacheBuster={props.cacheBuster} paths={props.paths} />
<Carbon.IncludeAssets:File
file={item}
assetPackage={props.assetPackage}
cacheBuster={props.cacheBuster}
disableCacheBusterForPreloadAsset={props.disableCacheBusterForPreloadAsset}
paths={props.paths}
/>
</Neos.Fusion:Collection>
`
}
4 changes: 3 additions & 1 deletion Resources/Private/Fusion/External/File.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ prototype(Carbon.IncludeAssets:File) < prototype(Neos.Fusion:Component) {
file = null
assetPackage = ${node.context.currentSite.siteResourcesPackageKey}
cacheBuster = ${Configuration.setting('Carbon.IncludeAssets.Default.CacheBuster')}
disableCacheBusterForPreloadAsset = ${Configuration.setting('Carbon.IncludeAssets.Default.DisableCacheBusterForPreloadAsset')}
assetPath = null

// This is a internal variable, please use `assetPath` for an single file
Expand All @@ -17,6 +18,7 @@ prototype(Carbon.IncludeAssets:File) < prototype(Neos.Fusion:Component) {
file = ${props.file}
assetPackage = ${props.assetPackage}
cacheBuster = ${props.cacheBuster}
disableCacheBusterForPreloadAsset = ${props.disableCacheBusterForPreloadAsset}
assetPath = ${props.assetPath ? props.assetPath : props.paths[this.assetKey][this.type]}

fileObject = ${Carbon.IncludeAssets.parseFilename(props.file)}
Expand Down Expand Up @@ -50,7 +52,7 @@ prototype(Carbon.IncludeAssets:File) < prototype(Neos.Fusion:Component) {
<Carbon.IncludeAssets:Internal.Tag.JS path={props.path} fileObject={props.fileObject} cacheBuster={props.cacheBuster} />
`
preload = afx`
<Carbon.IncludeAssets:Internal.Tag.ResourceHint rel='preload' path={props.path} fileObject={props.fileObject} cacheBuster={props.cacheBuster} />
<Carbon.IncludeAssets:Internal.Tag.ResourceHint rel='preload' path={props.path} fileObject={props.fileObject} cacheBuster={props.cacheBuster} disableCacheBusterForPreloadAsset={props.disableCacheBusterForPreloadAsset} />
`
modulePreload = afx`
<Carbon.IncludeAssets:Internal.Tag.ResourceHint rel='modulepreload' path={props.path} fileObject={props.fileObject} cacheBuster={props.cacheBuster} />
Expand Down
9 changes: 8 additions & 1 deletion Resources/Private/Fusion/Internal/Package.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ prototype(Carbon.IncludeAssets:Internal.Package) < prototype(Neos.Fusion:Compone
}
assetPackage = ${props.mergedConfig.Package == 'SitePackage' ? node.context.currentSite.siteResourcesPackageKey : props.mergedConfig.Package}
cacheBuster = ${props.mergedConfig.CacheBuster}
disableCacheBusterForPreloadAsset = ${props.mergedConfig.DisableCacheBusterForPreloadAsset}
paths = ${props.mergedConfig.Path}
collection = Neos.Fusion:RawCollection {
collection = ${['General', 'Backend', 'Live']}
Expand All @@ -36,7 +37,13 @@ prototype(Carbon.IncludeAssets:Internal.Package) < prototype(Neos.Fusion:Compone
}

renderer = afx`
<Carbon.IncludeAssets:Collection assetPackage={props.assetPackage} cacheBuster={props.cacheBuster} collection={props.collection} paths={props.paths} />
<Carbon.IncludeAssets:Collection
assetPackage={props.assetPackage}
cacheBuster={props.cacheBuster}
disableCacheBusterForPreloadAsset={props.disableCacheBusterForPreloadAsset}
collection={props.collection}
paths={props.paths}
/>
`
}
}
2 changes: 2 additions & 0 deletions Resources/Private/Fusion/Internal/Tag.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ prototype(Carbon.IncludeAssets:Internal.Tag) < prototype(Neos.Fusion:Component)
prototype(Carbon.IncludeAssets:Internal.Tag.ResourceHint) < prototype(Carbon.IncludeAssets:Internal.Tag) {
async = false
rel = null
disableCacheBusterForPreloadAsset = true
[email protected] = ${this.disableCacheBusterForPreloadAsset && this.fileObject && this.fileObject.type == 'PRELOADASSET' ? false : value}
@if.hasRel = ${this.rel}
renderer.resourceHint = ${'<link rel="' + props.rel + '" href="' + this.uri + '"' + props.attributes +' />'}
}
Expand Down

0 comments on commit b9d7b75

Please sign in to comment.