From 75a124b4490adb7d333046ecafbee209751b2bbe Mon Sep 17 00:00:00 2001
From: silverwind <me@silverwind.io>
Date: Sat, 25 Jan 2020 19:58:26 +0100
Subject: [PATCH] remove loadCSS and preload woff2 icon fonts (#9976)

loadCSS was used as a polyfill for rel=preload but it seems we only used
it on a single CSS file which did not help much. Changed the icon CSS to
a blocking load and preload the woff2 variants which does work in modern
browsers (Firefox currently needs the network.preload about:config
setting but should gain proper support soon).

Co-authored-by: zeripath <art27@cantab.net>
---
 public/vendor/VERSIONS                        |  3 ---
 public/vendor/librejs.html                    | 10 ---------
 public/vendor/plugins/cssrelpreload/LICENSE   | 21 -------------------
 .../cssrelpreload/cssrelpreload.min.js        |  2 --
 .../plugins/cssrelpreload/loadCSS.min.js      |  2 --
 templates/base/head.tmpl                      | 14 ++++---------
 templates/pwa/serviceworker_js.tmpl           |  2 --
 7 files changed, 4 insertions(+), 50 deletions(-)
 delete mode 100644 public/vendor/plugins/cssrelpreload/LICENSE
 delete mode 100644 public/vendor/plugins/cssrelpreload/cssrelpreload.min.js
 delete mode 100644 public/vendor/plugins/cssrelpreload/loadCSS.min.js

diff --git a/public/vendor/VERSIONS b/public/vendor/VERSIONS
index 7593f31491..54280b70e2 100644
--- a/public/vendor/VERSIONS
+++ b/public/vendor/VERSIONS
@@ -23,9 +23,6 @@ Version: 2.1.10
 File(s): /vendor/plugins/emojify/emojify.custom.js
 Version: 1.1.0
 
-File(s): /vendor/plugins/cssrelpreload/
-Version: 1.3.1
-
 File(s): /vendor/plugins/dropzone/dropzone.js
 Version: 4.2.0
 
diff --git a/public/vendor/librejs.html b/public/vendor/librejs.html
index ddaa8034f8..7d29b35c56 100644
--- a/public/vendor/librejs.html
+++ b/public/vendor/librejs.html
@@ -60,16 +60,6 @@
           <td><a href="http://www.freebsd.org/copyright/freebsd-license.html">Expat</a></td>
           <td><a href="https://github.com/Ranks/emojify.js/archive/1.1.0.tar.gz">emojify-1.1.0.tar.gz</a></td>
         </tr>
-        <tr>
-          <td><a href="./plugins/cssrelpreload/loadCSS.min.js">loadCSS.min.js</a></td>
-          <td><a href="http://www.freebsd.org/copyright/freebsd-license.html">Expat</a></td>
-          <td><a href="https://github.com/filamentgroup/loadCSS/archive/v1.3.1.tar.gz">loadCSS-1.3.1.tar.gz</a></td>
-        </tr>
-        <tr>
-          <td><a href="./plugins/cssrelpreload/cssrelpreload.min.js">cssrelpreload.min.js</a></td>
-          <td><a href="http://www.freebsd.org/copyright/freebsd-license.html">Expat</a></td>
-          <td><a href="https://github.com/filamentgroup/loadCSS/archive/v1.3.1.tar.gz">loadCSS-1.3.1.tar.gz</a></td>
-        </tr>
         <tr>
           <td><a href="./plugins/dropzone/dropzone.js">dropzone.js</a></td>
           <td><a href="https://github.com/enyo/dropzone/blob/master/LICENSE">Expat</a></td>
diff --git a/public/vendor/plugins/cssrelpreload/LICENSE b/public/vendor/plugins/cssrelpreload/LICENSE
deleted file mode 100644
index 733395b515..0000000000
--- a/public/vendor/plugins/cssrelpreload/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) @scottjehl, 2016 Filament Group
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/public/vendor/plugins/cssrelpreload/cssrelpreload.min.js b/public/vendor/plugins/cssrelpreload/cssrelpreload.min.js
deleted file mode 100644
index 1204401b09..0000000000
--- a/public/vendor/plugins/cssrelpreload/cssrelpreload.min.js
+++ /dev/null
@@ -1,2 +0,0 @@
-/*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */
-!function(a){if(a.loadCSS){var b=loadCSS.relpreload={};if(b.support=function(){try{return a.document.createElement("link").relList.supports("preload")}catch(b){return!1}},b.poly=function(){for(var b=a.document.getElementsByTagName("link"),c=0;c<b.length;c++){var d=b[c];"preload"===d.rel&&"style"===d.getAttribute("as")&&(a.loadCSS(d.href,d,d.getAttribute("media")),d.rel=null)}},!b.support()){b.poly();var c=a.setInterval(b.poly,300);a.addEventListener&&a.addEventListener("load",function(){b.poly(),a.clearInterval(c)}),a.attachEvent&&a.attachEvent("onload",function(){a.clearInterval(c)})}}}(this);
\ No newline at end of file
diff --git a/public/vendor/plugins/cssrelpreload/loadCSS.min.js b/public/vendor/plugins/cssrelpreload/loadCSS.min.js
deleted file mode 100644
index 7027506a30..0000000000
--- a/public/vendor/plugins/cssrelpreload/loadCSS.min.js
+++ /dev/null
@@ -1,2 +0,0 @@
-/*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
-!function(a){"use strict";var b=function(b,c,d){function e(a){return h.body?a():void setTimeout(function(){e(a)})}function f(){i.addEventListener&&i.removeEventListener("load",f),i.media=d||"all"}var g,h=a.document,i=h.createElement("link");if(c)g=c;else{var j=(h.body||h.getElementsByTagName("head")[0]).childNodes;g=j[j.length-1]}var k=h.styleSheets;i.rel="stylesheet",i.href=b,i.media="only x",e(function(){g.parentNode.insertBefore(i,c?g:g.nextSibling)});var l=function(a){for(var b=i.href,c=k.length;c--;)if(k[c].href===b)return a();setTimeout(function(){l(a)})};return i.addEventListener&&i.addEventListener("load",f),i.onloadcssdefined=l,l(f),i};"undefined"!=typeof exports?exports.loadCSS=b:a.loadCSS=b}("undefined"!=typeof global?global:this);
\ No newline at end of file
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl
index 523d83dd41..5a27467f3b 100644
--- a/templates/base/head.tmpl
+++ b/templates/base/head.tmpl
@@ -50,7 +50,6 @@
 	<meta name="go-import" content="{{.GoGetImport}} git {{.CloneLink.HTTPS}}">
 	<meta name="go-source" content="{{.GoGetImport}} _ {{.GoDocDirectory}} {{.GoDocFile}}">
 {{end}}
-
 	<script>
 	{{SafeJS `/*
 	@licstart  The following is the entire license notice for the
@@ -84,13 +83,13 @@
         for the JavaScript code in this page.
 	*/`}}
 	</script>
-
 	<link rel="shortcut icon" href="{{StaticUrlPrefix}}/img/favicon.png" />
 	<link rel="mask-icon" href="{{StaticUrlPrefix}}/img/gitea-safari.svg" color="#609926">
-	<link rel="preload" href="{{StaticUrlPrefix}}/vendor/assets/font-awesome/css/font-awesome.min.css" as="style" onload="this.rel='stylesheet'">
-	<noscript><link rel="stylesheet" href="{{StaticUrlPrefix}}/vendor/assets/font-awesome/css/font-awesome.min.css"></noscript>
+	<link rel="stylesheet" href="{{StaticUrlPrefix}}/vendor/assets/font-awesome/css/font-awesome.min.css">
 	<link rel="stylesheet" href="{{StaticUrlPrefix}}/vendor/assets/octicons/octicons.min.css">
-
+	<link rel="preload" as="font" href="{{StaticUrlPrefix}}/fomantic/themes/default/assets/fonts/icons.woff2" type="font/woff2">
+	<link rel="preload" as="font" href="{{StaticUrlPrefix}}/fomantic/themes/default/assets/fonts/outline-icons.woff2" type="font/woff2">
+	<link rel="preload" as="font" href="{{StaticUrlPrefix}}/vendor/assets/octicons/octicons.woff2?ef21c39f0ca9b1b5116e5eb7ac5eabe6" type="font/woff2">
 {{if .RequireSimpleMDE}}
 	<link rel="stylesheet" href="{{StaticUrlPrefix}}/vendor/plugins/simplemde/simplemde.min.css">
 {{end}}
@@ -98,8 +97,6 @@
 {{if .RequireTribute}}
 	<link rel="stylesheet" href="{{StaticUrlPrefix}}/vendor/plugins/tribute/tribute.css">
 {{end}}
-
-	<!-- Stylesheet -->
 	<link rel="stylesheet" href="{{StaticUrlPrefix}}/fomantic/semantic.min.css?v={{MD5 AppVer}}">
 	<link rel="stylesheet" href="{{StaticUrlPrefix}}/css/index.css?v={{MD5 AppVer}}">
 	<noscript>
@@ -125,9 +122,6 @@
 	<link rel="stylesheet" href="{{StaticUrlPrefix}}/vendor/plugins/vue-calendar-heatmap/vue-calendar-heatmap.css">
 {{end}}
 	<style class="list-search-style"></style>
-
-	<script src="{{StaticUrlPrefix}}/vendor/plugins/cssrelpreload/loadCSS.min.js"></script>
-	<script src="{{StaticUrlPrefix}}/vendor/plugins/cssrelpreload/cssrelpreload.min.js"></script>
 {{if .PageIsUserProfile}}
 	<meta property="og:title" content="{{.Owner.Name}}" />
 	<meta property="og:type" content="profile" />
diff --git a/templates/pwa/serviceworker_js.tmpl b/templates/pwa/serviceworker_js.tmpl
index 096628f2f0..72edf232bc 100644
--- a/templates/pwa/serviceworker_js.tmpl
+++ b/templates/pwa/serviceworker_js.tmpl
@@ -9,8 +9,6 @@ var urlsToCache = [
   '{{StaticUrlPrefix}}/vendor/plugins/clipboard/clipboard.min.js',
   '{{StaticUrlPrefix}}/vendor/plugins/codemirror/addon/mode/loadmode.js',
   '{{StaticUrlPrefix}}/vendor/plugins/codemirror/mode/meta.js',
-  '{{StaticUrlPrefix}}/vendor/plugins/cssrelpreload/cssrelpreload.min.js',
-  '{{StaticUrlPrefix}}/vendor/plugins/cssrelpreload/loadCSS.min.js',
   '{{StaticUrlPrefix}}/vendor/plugins/dropzone/dropzone.js',
   '{{StaticUrlPrefix}}/vendor/plugins/emojify/emojify.custom.js',
   '{{StaticUrlPrefix}}/vendor/plugins/highlight/highlight.pack.js',