StaticWebEpiserverPlugin 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package StaticWebEpiserverPlugin --version 2.0.0
NuGet\Install-Package StaticWebEpiserverPlugin -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StaticWebEpiserverPlugin" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StaticWebEpiserverPlugin --version 2.0.0
#r "nuget: StaticWebEpiserverPlugin, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StaticWebEpiserverPlugin as a Cake Addin
#addin nuget:?package=StaticWebEpiserverPlugin&version=2.0.0

// Install StaticWebEpiserverPlugin as a Cake Tool
#tool nuget:?package=StaticWebEpiserverPlugin&version=2.0.0

StaticWebEpiserverPlugin

Generate static website but still use EpiServer as your CMS for your editors

Introduction

Do you need a crisis web or handling peek load of users on your site? I have started develop a add-on for sites using EpiServer that will take everything you publish and make a static version of it. This way you get the instant publishing of a dynamic website and the performance and scalability of static websites in one go. It should (havn't yet test it) be possible to create the pages directory in your EpiServer site making it fully dynamic for things like search and filtering but static for general information.

Pro

  • Reliable serverside response time
  • Very easy to scale up
  • No database dependency for visitor
  • No serverside code requried
  • Very secure (hard to hack static pages)
  • Supports having some pages dynamic and others generated static (see UseRouting below)
  • Supports custom resource types (You can extend default or start from scratch using <allowedResourceTypes>)
  • Event driven page generation, always latest changes on your website (created when editor publish page or block)

Con/limitations

  • Only pages inheriting from PageData will trigger page write
  • Only block inheriting from BlockBata will trigger page write
  • Resource limitations:
    • css (only support dependencies declared in url())
    • javascript (no dependencies)

What functionality is provided in Plugin?

Below you can read more what StaticWebEpiserverPlugin can do today. If you are missing something or something is not working as expected, please let me know 😃

Generate static pages on publishing of Pages and Blocks

StaticWebEpiserverPlugin uses the PublishedContent event on IContentEvents to listen for changes that are published on your site. This way it will make sure your site is always up to date with what you have published in EpiServer. No need for busting caches or having your website running without cache do always show the lastest information. As long as your pages are inheriting from PageData and your blocks are inheriting from BlockData, StaticWebEpiserver will keep track of your changes.

Generate static pages on running scheduled job

StaticWebEpiserverPlugin are also providing a scheduled job for you to run that will generate alla pages below the home of your website. Pages that are not a child (or a child of a child, and so on) of your startpage it will not be included in the pages generated. To start the job, run the job called "Generate StaticWeb".

Having different views for StaticWeb and normal users

Using DisplayChannel

StaticWeb is registering a displaychannel called "StaticWeb" (See Header.cshtml and Header.staticweb.cshtml for examples on how to use it, can be found in EpiServerStaticWebExample repository). It is perfect for removing functionality that can't be used in a static website (like filitering or search). It also makes it possible for you to view how the page will look and work on the static version.

Using VisitorGroup

StaticWeb is registering a criteria called "StaticWeb user" under "Technical" category so that you can create your own vistor groups. Making it possible to show different content for page generation and other users. If you for example is using StaticWebEpiServerPlugin for create a static emergency/reserve website to use if everything else fails.

How to ignore page or block type?

By inherit from IStaticWebIgnoreGenerate iterface on a page or block type you will tell StaticWeb NOT to generate a static version of this type when publishing or running the scheduled job.

How to ignore page at runtime?

By inherit from IStaticWebIgnoreGenerateDynamically iterface on a page type you will tell StaticWebEpiServerPlugin that it MAY or MAY NOT generate a static version of this page when publishing or running the scheduled job. StaticWebEpiServerPlugin will call method ShouldGenerate for the page and if it returns true, it will generate a static version of the page when publishing or running the scheduled job. BUT if it returns false, it will not generate page AND also check (by calling ShouldDeleteGenerated) if it should remove any previously generated version of this page. See StandardPage.cs for example on how it can be used.

You can customize it using Events

We want people to be able to modify the use after their own liking. There for we support the use of events on the IStaticWebService. They will be called in the order specified below. You can read more on what is available at Issue #2

Find, download and generate resources

When generating a page, StaticWebEpiserverPlugin will find all client side resources required for the page to work, download them and store them in the output folder along with the pages.

Following markup will searched for resources

  • script element (src attribute)
  • link element (href attribute)
  • a element (href attribute)
  • img element (src attribute)
  • source element (srcset attribute)

Following resource types will be stored by default

  • css (and resources declared in url())
  • javascript (no dependencies)
  • Web fonts (woff and woff2)
  • Images (png, jpg, jpeg, jpe, gif, webp, svg)
  • documents (pdf)
  • Icons (ico)
  • Assembly Resources (WebResource.axd and ScriptResource.axd as long as resulting content type are allowed)

The rest will be ignored.

(Note: You can add or change supported resource types using <allowedResourceTypes>)

Requirements

  • EpiServer 11.15+
  • .Net 4.7.2+
  • All pages need to inherit from PageData
  • All blocks needs to inherit from BlockData
  • Website has to return pages, javascript and css as UTF-8
  • Must allow visits with user-agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36 StaticWebPlugin/0.1

Installation

NuGet

  • Add nuget package https://www.nuget.org/packages/StaticWebEpiserverPlugin/ to your solution.

  • Add below into: <configSections> element of web.config <section name="staticweb" type="StaticWebEpiserverPlugin.Configuration.StaticWebConfigurationSection" />

  • Add below to the same level as appSettings element (for example right below the end tag)

  • <staticweb>

    • <sites>
      • <add name="Test Website" url="http://localhost:49822/" outputPath="C:\websites\website1\wwwroot" resourceFolder="cache\v1" />
  • Change url and outputPath after your needs and you are ready to go 😃

  • You are ready to go 😃

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.1 300 12/4/2021
3.0.0 254 12/4/2021
2.0.0 403 5/27/2020
1.1.0 400 4/15/2020
1.0.1 391 3/30/2020
1.0.0 424 3/30/2020

## BREAKING CHANGE ##
Resource naming has been changed, set "StaticWeb:UseResourceUrl" to true and "StaticWeb:UseContentHash" to false to get old behavior.

New features:
- Added support for using static pages inside your EpiServer installation
- Added support for SVG-images (extension: .svg or content-type: image/svg+xml)
- Added support for content-type: x-javascript
- Added support for WebResource.axd and ScriptResource.axd
- Added Visitor Group support, new criteria called "StaticWeb user" under "Technical" category
- Now possible to specify sub folder for resources
- Possible to disable StaticWebEpiServerPlugin from web.config
- Default resource name is now a content hash
- Possible to use old resource naming (by only use resource url for naming)
- Possible to use both resource url and content hash for resource naming
- Using new configuration element in web.config for settings
- Add current number of pages generated ( in scheduled job )
- Added support for resources from href attribute on a-element
- Add ability to change supported file extensions and content types from default

Bug fixes:
- We now support both ' and " for resource finding
- Resources in CSS files are now added to references resources
- IStaticWebIgnoreGenerate and IStaticWebIgnoreGenerateDynamically are now supported in scheduled job also
- Scheduled job is not sending current referenced resources list to events (New property: CurrentResources)
- Scheduled job "Generate StaticWeb" changes place in menu everytime

Additional:
- Added extension StaticWebEpiserverPlugin.RequiredCssOnly to allow for extraction of required CSS Only (for example to use as inline on every page)