{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/5340","repository_url":"https://api.github.com/repos/aspnet/Mvc","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/5340/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/5340/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/5340/events","html_url":"https://github.com/aspnet/Mvc/issues/5340","id":180118758,"number":5340,"title":"Add an option to inline css file inside a Razor page","user":{"login":"gdoron","id":6141009,"avatar_url":"https://avatars.githubusercontent.com/u/6141009?v=3","gravatar_id":"","url":"https://api.github.com/users/gdoron","html_url":"https://github.com/gdoron","followers_url":"https://api.github.com/users/gdoron/followers","following_url":"https://api.github.com/users/gdoron/following{/other_user}","gists_url":"https://api.github.com/users/gdoron/gists{/gist_id}","starred_url":"https://api.github.com/users/gdoron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdoron/subscriptions","organizations_url":"https://api.github.com/users/gdoron/orgs","repos_url":"https://api.github.com/users/gdoron/repos","events_url":"https://api.github.com/users/gdoron/events{/privacy}","received_events_url":"https://api.github.com/users/gdoron/received_events","type":"User","site_admin":false},"labels":[{"id":70264662,"url":"https://api.github.com/repos/aspnet/Mvc/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":96169357,"url":"https://api.github.com/repos/aspnet/Mvc/labels/needs%20design","name":"needs design","color":"006b75","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/aspnet/Mvc/milestones/9","html_url":"https://github.com/aspnet/Mvc/milestones/Backlog","labels_url":"https://api.github.com/repos/aspnet/Mvc/milestones/9/labels","id":673495,"number":9,"title":"Backlog","description":"Items to be considered in future releases that are currently not assigned any specific milestone.","creator":{"login":"yishaigalatzer","id":1238711,"avatar_url":"https://avatars.githubusercontent.com/u/1238711?v=3","gravatar_id":"","url":"https://api.github.com/users/yishaigalatzer","html_url":"https://github.com/yishaigalatzer","followers_url":"https://api.github.com/users/yishaigalatzer/followers","following_url":"https://api.github.com/users/yishaigalatzer/following{/other_user}","gists_url":"https://api.github.com/users/yishaigalatzer/gists{/gist_id}","starred_url":"https://api.github.com/users/yishaigalatzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yishaigalatzer/subscriptions","organizations_url":"https://api.github.com/users/yishaigalatzer/orgs","repos_url":"https://api.github.com/users/yishaigalatzer/repos","events_url":"https://api.github.com/users/yishaigalatzer/events{/privacy}","received_events_url":"https://api.github.com/users/yishaigalatzer/received_events","type":"User","site_admin":false},"open_issues":200,"closed_issues":50,"state":"open","created_at":"2014-05-28T21:50:24Z","updated_at":"2016-10-26T21:18:42Z","due_on":null,"closed_at":null},"comments":13,"created_at":"2016-09-29T17:56:36Z","updated_at":"2016-11-01T08:50:00Z","closed_at":null,"body":"Hi,\n\nI just wrote a small TagHelper that inlines css files as it's one of the recommendations of PageSpeed by Google:\nhttps://developers.google.com/speed/docs/insights/InlineCSS \nhttps://developers.google.com/speed/docs/insights/OptimizeCSSDelivery\n\nIt would be nice if ASP.NET would have something like that baked into the framework and the existing `LinkTagHelper` which surely will be much more robust than my extremely simple, couple of minutes work:\n\n```\n[HtmlTargetElement(\"embedCss\")]\npublic class EmbedCssTagHelper : TagHelper\n{\n    private readonly IMemoryCache _memoryCache;\n    private readonly IHostingEnvironment _hostingEnvironment;\n    private const string CacheKeyPrefix = \"EmbedCss_\";\n    public string Href { get; set; }\n\n    public EmbedCssTagHelper(IMemoryCache memoryCache, IHostingEnvironment hostingEnvironment)\n    {\n        _memoryCache = memoryCache;\n        _hostingEnvironment = hostingEnvironment;\n    }\n\n    public override void Process(TagHelperContext context, TagHelperOutput output)\n    {\n        var cacheKey = CacheKeyPrefix + Href;\n        output.TagName = \"style\";\n        var content = _memoryCache.GetOrCreate(cacheKey, entry =>\n        {\n            if (_hostingEnvironment.IsStaging() || _hostingEnvironment.IsProduction())\n            {\n                Href = Href.Replace(\".css\", \".min.css\");\n            }\n\n            var path = _hostingEnvironment.WebRootPath+ Href;\n            var result = File.ReadAllText(path);\n            // Surely there are other ways, like watching the file system for changes...\n            // If you could reference a resource that shows how to do that it would be great!\n            entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(1));\n            entry.SetValue(result);\n            return result;\n        });\n\n        output.Content.SetHtmlContent(content);\n        output.TagMode = TagMode.StartTagAndEndTag;\n    }\n}\n```\n\nWhat do you think about it @Eilon?\n\nBTW, while writing the TagHelper was easy, I couldn't find why my TagHelper didn't get fire until I added `[HtmlTargetElement(\"embedCss\")]`, what should be the element name in the HTML if it wasn't specified?\n"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/257516334","html_url":"https://github.com/aspnet/Mvc/issues/5340#issuecomment-257516334","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/5340","id":257516334,"user":{"login":"gdoron","id":6141009,"avatar_url":"https://avatars.githubusercontent.com/u/6141009?v=3","gravatar_id":"","url":"https://api.github.com/users/gdoron","html_url":"https://github.com/gdoron","followers_url":"https://api.github.com/users/gdoron/followers","following_url":"https://api.github.com/users/gdoron/following{/other_user}","gists_url":"https://api.github.com/users/gdoron/gists{/gist_id}","starred_url":"https://api.github.com/users/gdoron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdoron/subscriptions","organizations_url":"https://api.github.com/users/gdoron/orgs","repos_url":"https://api.github.com/users/gdoron/repos","events_url":"https://api.github.com/users/gdoron/events{/privacy}","received_events_url":"https://api.github.com/users/gdoron/received_events","type":"User","site_admin":false},"created_at":"2016-11-01T08:50:00Z","updated_at":"2016-11-01T08:50:00Z","body":"@Eilon So what do you suggest? It seems like the community is blocked by the framework, unless we are going to copy paste the entire `LinkTagHelper` class (and its dependencies) which is really bad for maintenance.\r\n\r\nThanks."}}
{"actor":{"display_login":"gdoron"}}