作者:活的精彩的人2011_373 | 来源:互联网 | 2023-08-20 19:16
ImtryingtoimplementtheHttp2pushserverfunctionalityusingPushPromise.NET4.6.1,forthis
I'm trying to implement the Http2 push server functionality using "PushPromise" .NET 4.6.1, for this I have a "html extension" with Razor (we did not implement MVC only used the Razor engine to build the pages).
我正在尝试使用“PushPromise”.NET 4.6.1实现Http2推送服务器功能,为此我有一个带有Razor的“html扩展”(我们没有实现MVC只使用Razor引擎来构建页面)。
public static IHtmlString PushPromiseStylesheet(this HtmlHelper htmlHelper, string src, bool addDomElement = true)
{
var cOntext= HttpContext.Current;
var path = System.Web.Optimization.Styles.Url(src).ToString();
var headers = new NameValueCollection { { "accept-encoding", context.Request.Headers["accept-encoding"] } };
context.Response.PushPromise(path, "GET", headers);
var styleElement = $"";
return new HtmlString(addDomElement ? styleElement : String.Empty);
}
public static IHtmlString PushPromiseJavascript(this HtmlHelper htmlHelper, string src)
{
var cOntext= HttpContext.Current;
var path = System.Web.Optimization.Scripts.Url(src).ToString();
var headers = new NameValueCollection { { "accept-encoding", context.Request.Headers["accept-encoding"] } };
context.Response.PushPromise(path,"GET",headers);
var JavascriptElement = $"";
return new HtmlString(JavascriptElement);
}
public static IHtmlString PushPromiseImage(this HtmlHelper htmlHelper, string src, bool addDomElement = false)
{
var cOntext= HttpContext.Current;
var path = System.Web.Optimization.Scripts.Url(src).ToString();
var headers = new NameValueCollection { { "accept-encoding", context.Request.Headers["accept-encoding"] } };
context.Response.PushPromise(path,"GET",headers);
var imgElement = $"";
return new HtmlString(addDomElement ? imgElement : String.Empty);
}
public static IHtmlString PushPromiseWebFont(this HtmlHelper htmlHelper, string src, string type = null)
{
var cOntext= HttpContext.Current;
var path = System.Web.Optimization.Scripts.Url(src).ToString();
type = string.IsNullOrWhiteSpace(type) ? "font/woff2" : type;
var headers = new NameValueCollection { { "accept-encoding", context.Request.Headers["accept-encoding"] } };
context.Response.PushPromise(path, "GET", headers);
var fOntElement= $" ";
return new HtmlString(fontElement);
}
And in the of the page:
并在页面的中:
@Html.PushPromiseStylesheet("~/css/app/fonts.css")
@Html.PushPromiseStylesheet("~/css/landing.base.css")
@Html.PushPromiseStylesheet("~/css/landing.style.css")
@Html.PushPromiseImage("/assets/img/bg-ofertas.jpg")
@Html.PushPromiseImage("/assets/img/landings/v2/iphone.png")
@Html.PushPromiseImage("/assets/img/landings/v2/ipad-new.png")
@Html.PushPromiseImage("/assets/img/landings/v2/macbook-new.png")
@Html.PushPromiseWebFont("/assets/fonts/CredimejoraIcons.woff2?miydpz")
@Html.PushPromiseWebFont("/assets/fonts/centrale_sans_regular_italic-webfont.woff2")
@Html.PushPromiseWebFont("/assets/fonts/centrale_sans_bold_italic-webfont.woff2")
@Html.PushPromiseWebFont("/assets/fonts/centrale_sans_regular-webfont.woff2")
@Html.PushPromiseWebFont("/assets/fonts/centrale_sans_bold-webfont.woff2")
@Html.PushPromiseJavascript("/assets/js/public/libs/jquery.inputmask.bundle-3.3.6.2.js")
I have hosted the same project "without using PushPromise" (credimejorademo), and in another domain I have implemented PushPromise (aquituinmueble):
我已经托管了同一个项目“不使用PushPromise”(credimejorademo),而在另一个领域我实施了PushPromise(aquituinmueble):
https://www.webpagetest.org/video/compare.php?tests=170609_PD_e32f303e034aef3fef7140fef181a738,170609_FK_7d538ecdacf071cce320ad14bf97414c
1 个解决方案