Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds asp-append-version support #3581

Merged
merged 31 commits into from Jul 5, 2019

Conversation

deanmarcussen
Copy link
Member

This adds asp-append-version support to media, style, and script tag helpers, and liquid filters, through providing a replacement for the MVC DefaultFileVersionProvider, and adaptions to the various filters, tag helpers, and ResourceManager

It replaces #3172 as @jtkech has provided lots of advise as we've come up with a better way to achieve this.

It covers issues which are collected together in #3537 regarding asp-file-version support

Media is covered through changes to the ImageTagHelper

Scripts and styles, are covered through changes to the Tag Helpers and a new property on the ResourceSettings of UseAppendVersion so it can also be configured through code.

I've updated the admin theme and ResourceManifest to UseAppendVersion - it is helpful also for registered resources, as will provide a version tag when in debug mode and serving, for example jQuery which in debug mode does not have a version string in our local path to it. More updates to do to other Admin related views in other modules, if we want to use this as a default feature.

It also adds a cdn base path property to ResourceManager and site settings to allow only locally assets to be prefixed with a default cdn url. (to see in action just use your https://localhost address as the base)

And while I was there I added the code from O1 OrchardCMS/Orchard#8176 to support better resource bundling from issue #3434

@jtkech I've left #3172 open for the moment as we have so many discussions about further supporting blob storage. Cheers for all your help! (and probably more help with reviewing!)

…n. AppendVersion remains useful on ResourceManifest that also uses Version as when providing debug-src url's are not versioned
… so UseStaticFiles can resolve correct IFileProvider, in case another IFileProvider registered earlier (no conflict with media or custom registration in Cms.Web for example)
… file provider manifest to once per tenant = false
@jtkech
Copy link
Member

jtkech commented May 6, 2019

@deanmarcussen

Just tried, i could see the style / script appended versions when under the admin, looks very good. I may not have so much time this week (administrative things in late) but i will review it asap, maybe step by step.

Right now i just reviewed the AppendVersionFilter liquid filter, nothing very important, mainly to describe my findings when testing it.

…o provide additional path base information to IFileProviders if required.
@deanmarcussen
Copy link
Member Author

@jtkech Thanks for the quick look and comments!

I've since implemented the IVirtualPathBaseProvider discussed above and is working better in (I hope) all scenarios

  • OC Tag Helpers
  • Mvc Tag Helpers
  • Liquid filters and Liquid -> mvc bridge
  • Multi tenanted and single host

I also implemented the same IFileProvider pattern for the OrchardCore.Tenants.FileProvider feature as I had totally forgotten about it! Have also included the old request from you for the Manifest to be changed to DefaultTenantOnly = false

And done some code cleanup (my bad)

Cheers appreciate the time it takes to review! Busy week for me on other things as well.

@jtkech
Copy link
Member

jtkech commented May 6, 2019

@deanmarcussen

I like it 👍 just did some refactoring on my side that i will explain through comments or a review coming soon. Please don't push other updates because i did the changes on my side for testing, so would be better that i could push them to your branch, or create a branch on my side that you will merge.

@jtkech
Copy link
Member

jtkech commented May 7, 2019

@deanmarcussen

  • So, i did a review, mainly some renaming, and moving some implementations e.g to make ResourceManagement still independent of OC.

  • I tried the cdn url setting to use a cdn for our local static files and that still allow to append a version hash. I tried it by using http://localhost:xxxx, it works fine.

As said above i did the changes on my side for testing, so we will see tomorrow how we can share my work so that you can review it.

@deanmarcussen
Copy link
Member Author

@jtkech Great, review looks very good - I'm still figuring out where to put things in the many Orchard Projects.

Really good to move FileVersionProvider out of ResourceManagement - I wanted to but had no idea where to put it.

Also I had named it FileVersionProvider rather than DefaultFileVersionProvider as that was MVC's name for it, but it might be better as DefaultFileVersionProvider?

I think maybe your review allows me to clean up a few other things so maybe when you are finished reviewing, if you pull request my branch, then I can tidy up some more things that occur to me now.

Regardless I make no more commits to this PR while you are still looking through it.

Also still not sure if I need to add so many File Watchers for Not Found files, but seemed useful (especially for testing by dropping missing files into folders), but if you have any thoughts on this be great.

@jtkech
Copy link
Member

jtkech commented May 7, 2019

@deanmarcussen

I did some answers on the review.

Also I had named it FileVersionProvider rather than DefaultFileVersionProvider as that was MVC's name for it, but it might be better as DefaultFileVersionProvider?

I renamed it to ShellFileVersionProvider.

I think maybe your review allows me to clean up a few other things so maybe when you are finished reviewing, if you pull request my branch, then I can tidy up some more things that occur to me now.

Okay.

Also still not sure if I need to add so many File Watchers for Not Found files, but seemed useful (especially for testing by dropping missing files into folders), but if you have any thoughts on this be great.

Yes, useful in dev mode (or not) for files that are still physical files, so that the token is invalidated when the file is removed / added. Hmm, maybe not so useful in prod because most of the files are embedded, but there are app level static files, tenant specific ones and medias, so right now let keep it, will see.

Update: Do we have to update all razor / liquid views to use the append version attribute? Or later in another PR ;)

Update: I pushed my updates on your branch, please review them, i may have missed something, did wrong things, some comments not correctly updated, and maybe re-do some tests.

@jtkech
Copy link
Member

jtkech commented May 9, 2019

Note I realise I forget to do the LinkTagHelper so I do that tonight

I forgot it me too ;)

I let you test it, let me know when you are ready with this last change so that i can approve this PR, then for merging it we will have to wait for @sebastienros ;)

Update: Next PR

  • Make media azure tenant aware, blob images resizable and versionable, and compatible with our tag helpers. Maybe not so simple but i think it will be easier with this new base.

@deanmarcussen
Copy link
Member Author

deanmarcussen commented May 10, 2019

@jtkech Tested again this morning, and all working well, so for me it is ready. Cheers for your herlp getting it knocked into shape!

@sebastienros FYI, below is screenshot for Resource Cdn settings - this is the only visual change in the admin.

blog-resource-cdn-settings

Update: Next PR
Make media azure tenant aware, blob images resizable and versionable, and compatible with our tag helpers. Maybe not so simple but i think it will be easier with this new base.

Yes, @sebastienros as discussed, input when you are ready on design :)

Other Next PR
While we work on design for Azure, will update admin views / media picker / rich text editor filter / etc al to use append version

@Skrypt
Copy link
Contributor

Skrypt commented May 29, 2019

I agree that source maps should be generated separately from minified assets. The source maps should be only usefull for dev purpose and never be published on prod websites. The gulp pipeline as it is has been migrated from 01 and has only been slightly modified for OC. I'm opening an issue for this and other issues reported with the gulp pipeline.

@Skrypt
Copy link
Contributor

Skrypt commented May 29, 2019

So basically this feature is : cache busting for assets.

@jtkech
Copy link
Member

jtkech commented May 30, 2019

Yes, and the new conflict is because of my last PR ;)

@Skrypt
Copy link
Contributor

Skrypt commented May 30, 2019

Ohh you bad french people! 🍪 🍪

@Skrypt
Copy link
Contributor

Skrypt commented May 30, 2019

Ok I tested this PR and with Liquid so far everything works fine.

@deanmarcussen
Copy link
Member Author

@Skrypt Yes cache busting for js/css and media assets

Cheers for testing 😄

I'll resolve merge conflict shortly

@deanmarcussen
Copy link
Member Author

Oh also, you should be able to see it working with razor on the admin page layout
view-source:https://localhost:44300/admin

e.g.

<link href="/TheAdmin/Styles/TheAdmin.css?v=zJ9dsRDaOTdF7jaJ5f3nHnoHp2HRzSkgSeXTZmg4sy0" rel="stylesheet" type="text/css" />

<!-- This script can't wait to the footer -->
<script src="/TheAdmin/Scripts/userPreferencesLoader.js?v=eER9OO6zWGKaIq1RlNjImsrWN9y2oTgQKg2TrJnDUWk" type="text/javascript"></script>

Note Only the admin Layout.cshtml has been altered to use asp-append-version

@Skrypt
Copy link
Contributor

Skrypt commented May 30, 2019

I was looking at the assets for our Admin theme and there's probably things that could be bundled together. The frontend themes have the same issue but we kept the templates as close as they we're built without really optimizing them properly by using only one .js file and one .css file per template. We have a gulp pipeline but we are not using it optimally. As for CDN for assets, the more you add external libraries in your HTML the more requests you get on your page and the slower it gets. So far it has always been faster for me to bundle everything in one file if I could.

I'm going to work on something today. At least fix the issues that we all have with Bootstrap versions.

@deanmarcussen
Copy link
Member Author

Couldn't agree more.
Maybe one site / one vendor file with good cache headers, and cache busting, is my preferred solution, though I have been experimenting recently with using bootstrap and common vendor files from their cdn's in the hope that the end user already has it cached. Ruins the generic seo speed tests, as they never cache etc.

Good luck in the seventh circle of npm hell!

@Skrypt
Copy link
Contributor

Skrypt commented Jun 23, 2019

I think @sebastienros wants to look at the files watcher code before merging. It's working nicely on my website on prod as of now but I'm not using Azure Blob Storage yet.

@deanmarcussen
Copy link
Member Author

ah good to know it's working!

The file watcher code is straight out of the asp-net default handler.

I think it watches every 4 seconds (might be 2).

I do question how useful it is to have a file watcher running on the media dir. Could just as easily do the cache clearing from the MediaFileStore on file upload. Might work better with Blob Storage if it did that as well

@sebastienros
Copy link
Member

Please merge when the conflicts are solved. We'll still need to add the CDN settings for the Media items.

@jtkech
Copy link
Member

jtkech commented Jul 4, 2019

Okay, i will do

# Conflicts:
#	src/OrchardCore.Modules/OrchardCore.Media/Startup.cs
#	src/OrchardCore/OrchardCore.Mvc.Core/Startup.cs
@jtkech jtkech merged commit b3508d5 into OrchardCMS:dev Jul 5, 2019
@deanmarcussen deanmarcussen deleted the file-version-providers branch July 7, 2019 14:35
scleaver pushed a commit to scleaver/OrchardCore that referenced this pull request Aug 22, 2019
* MediaFileStoreVersionProvider and FileVersionHashProvider

* WIP. Add IFileVersion to ResourceManager and Tag Helpers

* WIP Update ResourceManifest and admin layout to use asp-append-version. AppendVersion remains useful on ResourceManifest that also uses Version as when providing debug-src url's are not versioned

* create IModuleStaticFileProvider and provide registration identifiers so UseStaticFiles can resolve correct IFileProvider, in case another IFileProvider registered earlier (no conflict with media or custom registration in Cms.Web for example)

* WIP. Media ImageHelper working but needs further testing

* add ImageVersionProcessor suggest by jtkech. Tested works well

* Fixes OrchardCMS#3434 Setting the right resource key in debug mode - added OrchardCMS#8177 / OrchardCMS#8177 from Orchard V1

* add liquid tag helper for append_version

* updated LiquidFilter to work via httpContextAccessor to support media within markdown & html body

* implement cache / tidy up mediafilter

* remove IFileVersionHashProvider, and Replace, rather than remove and add the OC FileVersionProvider

* renamed MediaFileImageProvider to MediaResizingFileProvider

* add CdnBaseUrl  support for prepending a base cdn url to assets

* update documentation, and support append-version with AssertUrl Helper

* documentation tweaks

* more documentation tweaks

* add support for tenant static file provider, and change tenant static file provider manifest to once per tenant = false

* Add support for IVirtualPathBaseProvider as a better generic filter to provide additional path base information to IFileProviders if required.

* Code cleanup

* Refactoring

* Minor changes.

* Refactoring ShellFileVersionProvider

* Refactoring, rename ImageTagHelper Attribute asp-append-version

* Also use a shared cache for module static files.

* Minor change.

* Add support for AppendVersion to Link Tag Helper

* Little formatting after merging dev.
MatthijsKrempel pushed a commit to MatthijsKrempel/OrchardCore that referenced this pull request Dec 23, 2019
* MediaFileStoreVersionProvider and FileVersionHashProvider

* WIP. Add IFileVersion to ResourceManager and Tag Helpers

* WIP Update ResourceManifest and admin layout to use asp-append-version. AppendVersion remains useful on ResourceManifest that also uses Version as when providing debug-src url's are not versioned

* create IModuleStaticFileProvider and provide registration identifiers so UseStaticFiles can resolve correct IFileProvider, in case another IFileProvider registered earlier (no conflict with media or custom registration in Cms.Web for example)

* WIP. Media ImageHelper working but needs further testing

* add ImageVersionProcessor suggest by jtkech. Tested works well

* Fixes OrchardCMS#3434 Setting the right resource key in debug mode - added OrchardCMS#8177 / OrchardCMS#8177 from Orchard V1

* add liquid tag helper for append_version

* updated LiquidFilter to work via httpContextAccessor to support media within markdown & html body

* implement cache / tidy up mediafilter

* remove IFileVersionHashProvider, and Replace, rather than remove and add the OC FileVersionProvider

* renamed MediaFileImageProvider to MediaResizingFileProvider

* add CdnBaseUrl  support for prepending a base cdn url to assets

* update documentation, and support append-version with AssertUrl Helper

* documentation tweaks

* more documentation tweaks

* add support for tenant static file provider, and change tenant static file provider manifest to once per tenant = false

* Add support for IVirtualPathBaseProvider as a better generic filter to provide additional path base information to IFileProviders if required.

* Code cleanup

* Refactoring

* Minor changes.

* Refactoring ShellFileVersionProvider

* Refactoring, rename ImageTagHelper Attribute asp-append-version

* Also use a shared cache for module static files.

* Minor change.

* Add support for AppendVersion to Link Tag Helper

* Little formatting after merging dev.
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.

None yet

4 participants