Skip to content

Implements resource file hash-based cache busting#7564

Merged
DaRosenberg merged 1 commit into
devfrom
feature/cachebuster
Mar 7, 2017
Merged

Implements resource file hash-based cache busting#7564
DaRosenberg merged 1 commit into
devfrom
feature/cachebuster

Conversation

@DaRosenberg

Copy link
Copy Markdown
Member

This PR adds automatic file hash-based cache busting to the Orchard resource manager.

The resource manager now uses a new abstraction IResourceFileHashProvider to add a file content hash to the query string of URLs for any scripts and stylesheets sourced from the local file system. The default implementation ResourceFileHashProvider provides a simple but efficient (and thread-safe) implementation, which uses stream-based MD5 hashing, and caches generated hashes based on the last modified time on the file on disk.

Resource file hashing can be disabled/enabled through a new site setting, exposed in the settings UI. It will be enabled by default for new sites, but not for existing sites.

@DaRosenberg DaRosenberg changed the title Implemented resource file hash-based cache busting. Implemented resource file hash-based cache busting Feb 10, 2017
@DaRosenberg DaRosenberg changed the title Implemented resource file hash-based cache busting Implements resource file hash-based cache busting Feb 10, 2017
@DaRosenberg
DaRosenberg merged commit 514e4fa into dev Mar 7, 2017
@DaRosenberg
DaRosenberg deleted the feature/cachebuster branch March 7, 2017 20:49
@jbuck79

jbuck79 commented Jun 28, 2017

Copy link
Copy Markdown

Is there a reason why this never made it into the 1.10.2 release? This code fixes #3954 and it would be really nice to have it.

I copied over just this code from StylesheetBindingStrategy (lines 92-100):

var shape = ((dynamic)displayContext.Value);
      var output = displayContext.ViewContext.Writer;
      ResourceDefinition resource = shape.Resource;
      string url = shape.Url;
      string condition = shape.Condition;
      Dictionary<string, string> attributes = shape.TagAttributes;
      ResourceManager.WriteResource(output, resource, url ?? hit.fileVirtualPath, condition, attributes);
      return null;

And it works. But my team tries not to modify the Orchard source code whenever possible to make merging in new releases easier.

Would the fix for #3954 be more likely to make it into an official release if I submitted a pull request with just that bit of code?

HermesSbicego-Laser pushed a commit to LaserSrl/Orchard that referenced this pull request Jan 14, 2022
# Conflicts:
#	src/Orchard.Tests/UI/Resources/ResourceManagerTests.cs
#	src/Orchard.Web/Core/Shapes/CoreShapes.cs
#	src/Orchard/UI/Resources/ResourceDefinition.cs
#	src/Orchard/UI/Resources/ResourceManager.cs
#	src/Orchard/UI/Resources/ResourceRequiredContext.cs
MatteoPiovanelli added a commit to LaserSrl/Orchard that referenced this pull request Jan 18, 2022
commit 580e478
Author: Hermes Sbicego <[email protected]>
Date:   Fri Jan 14 10:53:43 2022 +0100

    GetPhysicalPath returns error if url contains '?' (OrchardCMS#8526)

    * GetPhysicalPath returns error if url contains '?'

    Fixes

    * Update ResourceDefinition.cs

    Co-authored-by: Sébastien Ros <[email protected]>
    Co-authored-by: matteo.piovanelli <[email protected]>
    # Conflicts:
    #	src/Orchard/UI/Resources/ResourceDefinition.cs

commit 8c54830
Author: HermesSbicego-Laser <[email protected]>
Date:   Mon Jan 17 08:52:38 2022 +0100

    prevent the "Cannot set properties of null (setting 'dir')" error if getBody() function return null, somehow

commit cca674d
Author: HermesSbicego-Laser <[email protected]>
Date:   Fri Jan 14 13:55:58 2022 +0100

    Bootstrap 4.6.1 jQuery 3.6.0 jQueryUI 1.13.0 CDN + local files

commit 41bfc1e
Author: HermesSbicego-Laser <[email protected]>
Date:   Thu Jan 13 18:47:03 2022 +0100

    downgrade to bootstrap 4.6.0 cause ajaxaspnetcdn does not have 4.6.1 ready to use

commit 5b27bec
Author: HermesSbicego-Laser <[email protected]>
Date:   Thu Jan 13 18:48:14 2022 +0100

    - removed Ssl parameter

commit 7f86cf4
Author: Hermes Sbicego <[email protected]>
Date:   Mon Jan 10 18:08:52 2022 +0100

    GetPhysicalPath returns error if url contains '?'

    Fixes

commit 59704bd
Author: Lombiq <[email protected]>
Date:   Thu Aug 29 23:53:55 2019 +0200

    Framework/UI/Resources: Removing ResourceDefinition.CdnSupportsSsl

    Discussion: OrchardCMS#6941

    # Conflicts:
    #	src/Orchard.Tests/UI/Resources/ResourceManagerTests.cs
    #	src/Orchard.Web/Core/Shapes/CoreShapes.cs
    #	src/Orchard/UI/Resources/ResourceRequiredContext.cs

commit da3bc5a
Author: Lombiq <[email protected]>
Date:   Thu Aug 15 23:59:46 2019 +0200

    Framework/Resources: Fixing a regression with Style.Include, so it supports paths with a query string again, fixes OrchardCMS#8231

commit 862c127
Merge: 2c71619 71ee123
Author: HermesSbicego-Laser <[email protected]>
Date:   Thu Jan 13 17:34:31 2022 +0100

    Merge branch 'cherrypick/StaticFileHash' into upgrade/JQuery3Bootstrap4

commit 71ee123
Author: HermesSbicego-Laser <[email protected]>
Date:   Thu Jan 13 17:33:55 2022 +0100

    cherrypick for StaticFileHash

commit 39748fc
Author: Daniel Stolt <[email protected]>
Date:   Tue Mar 7 21:49:06 2017 +0100

    Implemented resource file hash-based cache busting. (OrchardCMS#7564)

    # Conflicts:
    #	src/Orchard.Tests/UI/Resources/ResourceManagerTests.cs
    #	src/Orchard.Web/Core/Shapes/CoreShapes.cs
    #	src/Orchard/UI/Resources/ResourceDefinition.cs
    #	src/Orchard/UI/Resources/ResourceManager.cs
    #	src/Orchard/UI/Resources/ResourceRequiredContext.cs

commit 2c71619
Author: HermesSbicego-Laser <[email protected]>
Date:   Thu Jan 13 12:54:02 2022 +0100

    Updates jquery.mjs.nestedSortable.js to latest version

commit 6344998
Author: HermesSbicego-Laser <[email protected]>
Date:   Thu Jan 13 08:58:52 2022 +0100

    Uses on("unload", handler) instead of unload(handler) because the last one was removed in jquery 3

commit 2690dc4
Author: HermesSbicego-Laser <[email protected]>
Date:   Thu Jan 13 08:28:50 2022 +0100

    - csproj file

commit 92dab11
Author: HermesSbicego-Laser <[email protected]>
Date:   Wed Jan 12 16:50:28 2022 +0100

    Gulpfile.js restored to its original version: it does not support js modules so why bootstrap transpilation has been removed from gulp pipeline. The original bootstrap distribution files have been committed also.

commit 2eb7330
Author: HermesSbicego-Laser <[email protected]>
Date:   Wed Jan 12 16:46:00 2022 +0100

    Adds original Bootstrap js and css
    Removes Bootstrap from Gulp pipeline cause it does not support js modules

commit a8aa12b
Author: HermesSbicego-Laser <[email protected]>
Date:   Tue Jan 11 08:57:02 2022 +0100

    Adds ParentType property to LayoutEditor_Template_Children shape so it can know the type of its container and behave accordingly

commit 60b74b3
Author: HermesSbicego-Laser <[email protected]>
Date:   Tue Jan 11 08:45:49 2022 +0100

    refactor

    # Conflicts:
    #	src/Gulpfile.js

commit f01950b
Author: HermesSbicego-Laser <[email protected]>
Date:   Tue Jan 11 08:42:06 2022 +0100

    - refactor

commit 97f0eee
Author: HermesSbicego-Laser <[email protected]>
Date:   Mon Jan 10 17:45:43 2022 +0100

    Removes default-grid.css from admin views of Layout editor because in conflict with bootstrap grid system used in admin
    Fixes html classes in order to work with bootstrap 4.x

commit 1671d9b
Author: HermesSbicego-Laser <[email protected]>
Date:   Mon Jan 10 15:19:16 2022 +0100

    col-xs-* changed into col-sm-* bevause was dismissed in bootstrap 4.x
    float:left was removed from bootstrap 4.x col-* rule. now moved into Layouts styles

    # Conflicts:
    #	src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.js
    #	src/Orchard.Web/Modules/Orchard.Layouts/Scripts/LayoutEditor.min.js
    #	src/Orchard.Web/Modules/Orchard.Layouts/Styles/LayoutEditor.css
    #	src/Orchard.Web/Modules/Orchard.Layouts/Styles/LayoutEditor.min.css

commit be752f1
Author: HermesSbicego-Laser <[email protected]>
Date:   Mon Jan 10 13:40:09 2022 +0100

    Adds Assets for jquery-3.6.0.js _interactions.scss

commit eb381d6
Author: HermesSbicego-Laser <[email protected]>
Date:   Mon Jan 10 13:37:28 2022 +0100

    - jQuery 3.6, JQueryUI 1.13, Bootstrap 4.6

    # Conflicts:
    #	src/Gulpfile.js
    #	src/Orchard.Web/Modules/Orchard.Layouts/Scripts/Models.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/Calendars/jquery.calendars.min.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/jquery-ui.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/jquery.fileupload-full.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/jquery.fileupload-full.min.js
    #	src/Package.json

commit c28c0e7
Author: Niranjan Kala <[email protected]>
Date:   Fri May 3 00:41:26 2019 +0530

    Issue/upgrade jquery (OrchardCMS#8183)

    # Conflicts:
    #	src/Orchard.Web/Modules/Orchard.Resources/Bootstrap.cs
    #	src/Orchard.Web/Modules/Orchard.Resources/Orchard.Resources.csproj
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/bootstrap.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/bootstrap.min.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/jquery-ui.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/jquery-ui.min.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/jquery.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Scripts/jquery.min.js
    #	src/Orchard.Web/Modules/Orchard.Resources/Styles/bootstrap.css
    #	src/Orchard.Web/Modules/Orchard.Resources/Styles/bootstrap.min.css
    #	src/Orchard.Web/Modules/Orchard.Resources/Styles/jquery-ui.css
    #	src/Orchard.Web/Modules/Orchard.Resources/Styles/jquery-ui.min.css
    #	src/Orchard.Web/Modules/Orchard.Resources/jQuery.cs
HermesSbicego-Laser pushed a commit to LaserSrl/Orchard that referenced this pull request Sep 20, 2022
(cherry picked from commit 514e4fa)

# Conflicts:
#	src/Orchard.Tests/UI/Resources/ResourceManagerTests.cs
#	src/Orchard.Web/Core/Shapes/CoreShapes.cs
#	src/Orchard/UI/Resources/ResourceDefinition.cs
#	src/Orchard/UI/Resources/ResourceManager.cs
#	src/Orchard/UI/Resources/ResourceRequiredContext.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants