-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #61 CDN support by adding a MediaProvider and CacheKey pipeline a…
…nd made it easy to enable this with a separate WebP CDN config
- Loading branch information
1 parent
0d6d3c0
commit 5ce6bf5
Showing
12 changed files
with
167 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/Dianoga/Default Config Files/Dianoga.WebP.CDN.config.disabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- | ||
Configures Dianoga to support WebP on a CDN | ||
--> | ||
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> | ||
<sitecore> | ||
<pipelines> | ||
<!-- Run the Sync processor first so that no other Sitecore processors are run for webp --> | ||
<getMediaStream> | ||
<processor type="Dianoga.Invokers.GetMediaStreamSync.OptimizeImage, Dianoga" patch:before="processor[1]" /> | ||
</getMediaStream> | ||
<!-- Generate a unique HTML cache key for renderings since the links will have query string extension=webp --> | ||
<mvc.renderRendering> | ||
<processor | ||
type="Dianoga.WebP.Pipelines.GenerateCacheKey, Dianoga" | ||
patch:after="processor[@type='Sitecore.Mvc.Pipelines.Response.RenderRendering.GenerateCacheKey, Sitecore.Mvc']" /> | ||
</mvc.renderRendering> | ||
</pipelines> | ||
|
||
<mediaLibrary> | ||
<!-- Add query string "extension=webp" to media links if the browser supports it for a unique CDN cache key. --> | ||
<mediaProvider | ||
type="Dianoga.WebP.MediaProvider, Dianoga" | ||
patch:instead="mediaProvider[@type='Sitecore.Resources.Media.MediaProvider, Sitecore.Kernel']"/> | ||
</mediaLibrary> | ||
|
||
</sitecore> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,71 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net452;net462;net471</TargetFrameworks> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<Description>Automatic media library image file optimization for Sitecore</Description> | ||
<Version>5.0.0-rc.4</Version> | ||
<Authors>Kam Figy, Mark Gibbons</Authors> | ||
<PackageProjectUrl>https://github.com/kamsar/Dianoga</PackageProjectUrl> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<RepositoryUrl>https://github.com/kamsar/Dianoga</RepositoryUrl> | ||
<PackageIconUrl>https://kamsar.net/nuget/dianoga/logo.png</PackageIconUrl> | ||
<PackageTags>sitecore optimization</PackageTags> | ||
<Copyright>Copyright 2020</Copyright> | ||
<Company /> | ||
<Product /> | ||
</PropertyGroup> | ||
<ItemGroup Condition="'$(TargetFramework)' == 'net452'"> | ||
<PackageReference Include="Sitecore.Kernel"> | ||
<Version>8.2.180406</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetFramework)' == 'net462'"> | ||
<PackageReference Include="Sitecore.Kernel"> | ||
<Version>9.0.180604</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Sitecore.XA.Foundation.MediaRequestHandler"> | ||
<Version>3.8.1</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetFramework)' == 'net471'"> | ||
<PackageReference Include="Sitecore.Kernel"> | ||
<Version>9.3.0</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Sitecore.XA.Foundation.MediaRequestHandler"> | ||
<Version>9.3.0</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Configuration" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Web" /> | ||
<Reference Include="System.XML" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="Default Config Files\*" PackagePath="content\App_Config\Include\Dianoga" /> | ||
<Content Include="Dianoga Tools\**\*" Exclude="Dianoga Tools\SVGO\**\*" PackagePath="content\App_Data\Dianoga Tools" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<TargetFrameworks>net452;net462;net471</TargetFrameworks> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<Description>Automatic media library image file optimization for Sitecore</Description> | ||
<Version>5.0.0-rc.4</Version> | ||
<Authors>Kam Figy, Mark Gibbons</Authors> | ||
<PackageProjectUrl>https://github.com/kamsar/Dianoga</PackageProjectUrl> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<RepositoryUrl>https://github.com/kamsar/Dianoga</RepositoryUrl> | ||
<PackageIconUrl>https://kamsar.net/nuget/dianoga/logo.png</PackageIconUrl> | ||
<PackageTags>sitecore optimization</PackageTags> | ||
<Copyright>Copyright 2020</Copyright> | ||
<Company /> | ||
<Product /> | ||
</PropertyGroup> | ||
<ItemGroup Condition="'$(TargetFramework)' == 'net452'"> | ||
<PackageReference Include="Sitecore.Kernel"> | ||
<Version>8.2.180406</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Sitecore.Mvc"> | ||
<Version>8.2.180406</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetFramework)' == 'net462'"> | ||
<PackageReference Include="Sitecore.Kernel"> | ||
<Version>9.0.180604</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Sitecore.Mvc"> | ||
<Version>9.0.180604</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Sitecore.XA.Foundation.MediaRequestHandler"> | ||
<Version>3.8.1</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(TargetFramework)' == 'net471'"> | ||
<PackageReference Include="Sitecore.Kernel"> | ||
<Version>9.3.0</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Sitecore.Mvc"> | ||
<Version>9.3.0</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Sitecore.XA.Foundation.MediaRequestHandler"> | ||
<Version>9.3.0</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Configuration" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Web" /> | ||
<Reference Include="System.XML" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="Default Config Files\*" PackagePath="content\App_Config\Include\Dianoga" /> | ||
<Content Include="Dianoga Tools\**\*" Exclude="Dianoga Tools\SVGO\**\*" PackagePath="content\App_Data\Dianoga Tools" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Remove="Default Config Files\Dianoga.WebP.CDN.config.disabled" /> | ||
</ItemGroup> | ||
</Project> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using Dianoga.Helpers; | ||
using Dianoga.WebP; | ||
|
||
namespace Dianoga.Optimizers.Pipelines.DianogaWebP | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Web; | ||
using Sitecore.Resources.Media; | ||
|
||
namespace Dianoga.WebP | ||
{ | ||
public static class Helpers | ||
{ | ||
|
||
public static bool BrowserSupportsWebP(this HttpContext context) | ||
{ | ||
return context?.Request.AcceptTypes != null && context.Request.AcceptTypes.Contains("image/webp"); | ||
} | ||
|
||
public static bool BrowserSupportsWebP(this MediaOptions mediaOptions) | ||
{ | ||
return mediaOptions.GetCustomExtension() == "webp"; | ||
} | ||
|
||
public static string GetCustomExtension(this MediaOptions mediaOptions) | ||
{ | ||
return mediaOptions.CustomOptions["extension"]; | ||
} | ||
} | ||
} |
Oops, something went wrong.