GithubHelp home page GithubHelp logo

bradmb / server-push-view-engine Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 18 KB

An ASP.NET Razor view engine wrapper that adds HTTP/2 preload headers for your javascript, css, and image elements

Home Page: https://bradmb.github.io/server-push-view-engine/

License: MIT License

C# 100.00%
asp-net-mvc asp-net razor razorengine razor-engine http2 http2-push csharp

server-push-view-engine's Introduction

Server Push View Engine

Introduction

I'm a big fan of HTTP/2. We run NGINX in front of our services with HTTP/2 enabled, and I've been waiting for them to announce support for server push when using NGINX as a proxy.

With the release of NGINX 1.13.9, that day has come. So to celebrate, I created a wrapper for the ASP.NET Razor view engine so you can dynamically add the HTTP/2 preload headers to your project without having to write custom header code for every page that you want to have javascript, images, or css files preloaded.

Installation

Simplty add this project to your solution and reference it in your main project. Then in your Glboal.asax.cs file, add this to the bottom of your Application_Start():

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new PushViewEngine());

Enabling On Specific Files

If you don't want all of your script, image, and style tags to automatically be included in the HTTP/2 preload headers, you can disable automatic inclusion by initializing the PushViewEngine() like so:

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new PushViewEngine(requirePrefix: true));

Then, in your tags that you want included in the HTTP/2 preload, simply append this tag:

data-http2-push="true"

So, on a script tag, this would look like:

<script src="myscript.js" data-http2-push="true" type="application/javascript"></script>

server-push-view-engine's People

Contributors

bradmb avatar

Watchers

 avatar  avatar

Forkers

crazyants

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.