GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - BibliTech/VersionedFileProvider: A File Provider that allow custom subpath.

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
BibliTech.VersionedFileProvider.Demo
BibliTech.VersionedFileProvider.Demo
 
 
BibliTech.VersionedFileProvider
BibliTech.VersionedFileProvider
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
VersionedFileProvider.sln
VersionedFileProvider.sln
 
 

Repository files navigation

VersionedFileProvider is a simple and lightweight IFileProvider wrapper for ASP.NET Core that allows you to remove or transform certain part of the file path. The package also expose a more generalized IPathTransformFileProvider and BasePathTransformFileProvider if you want a different path transformation.

screenshot

Why?

ASP.NET Core provides asp-append-version attribute so you can "drop" file cache (either browser cache or server cache or even services like Cloudflare cache) of CSS and Javascript files. However, with ES6 module import, this does not work:

// Content of /js/app.js

import { Common } from "./../common.js"; // Cannot use asp-append-version here

In development machine, it is not a problem to disable cache. However, for production environment, there is no simple way to clear it without modifying every Javascript file. That's why I think of appending a manual version on the top file path only:

<script type="module" src="~/js/v1/app.js" asp-append-version="true"></script>

This way, when you increase the version in the path, all the modules' paths are updated accordingly. However you need a way to serve such files when in reality, the server file system only contains /js folder.

Installation

Nuget package:

Install-Package BibliTech.VersionedFileProvider

Note: the library itself is very simple. If you don't want to include external reference, simply copy the content of VersionedFileProvider.cs and BasePathTransformFileProvider.cs.

Usage

You can check the Demo project to see how it is used.

Set as File Provider

VersionedFileProvider accepts an underlying IFileProvider. You can also use a folder path string, it will automatically create a PhysicalFileProvider for that folder. In usual case, you will want to use WebRootFileProvider for that.

var versionedFileProvider = new VersionedFileProvider(env.WebRootFileProvider);
app.UseStaticFiles(new StaticFileOptions()
{
    FileProvider = versionedFileProvider,
});

Set the WebRootFileProvider

If you want asp-append-version to work with this custom FileProvider, you will need to set it to IWebHostEnvironment.WebRootFileProvider. It is confirmed by the ASP.NET Core team.

env.WebRootFileProvider = versionedFileProvider;

Custom Version Expression or Transformation

By default, VersionedFileProvider uses a RegEx and simply remove every path segment that matches with it:

public Regex VersionRegex { get; set; } = new Regex(@"^v[0-9\.]+");

The default version match anything that starts with v and follows by 0-9 and dot (.) character, so your path is safe if you happen to have something like version or variant. You can change the VersionRegex property, or implement a FileProvider yourself by extending BasePathTransformFileProvider and override TransformSubpath method.

About

A File Provider that allow custom subpath.

Resources

Readme
MIT license
Activity
Custom properties

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.