Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce server request #16360

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions modules/ui_gradio_extensions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import gradio as gr

from modules import localization, shared, scripts, util
Expand Down Expand Up @@ -49,12 +50,21 @@ def stylesheet(fn):
return head


re_preconnect = re.compile(rb'<link\s+rel="preconnect"\s+href="([^"]+)"(?:\s+[^>]*)?/?>')


def reload_javascript():
js = javascript_html()
css = css_html()

def template_response(*args, **kwargs):
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)

# remove preconnects
res.body = re_preconnect.sub(b'', res.body)
# replace iframeResizer with local version
res.body = res.body.replace(b'src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.6/iframeResizer.contentWindow.min.js"', b'src="webui-assets/js/iframe-resizer/4.3.6/iframeResizer.contentWindow.min.js"')

res.body = res.body.replace(b'</head>', f'{js}<meta name="referrer" content="no-referrer"/></head>'.encode("utf8"))
res.body = res.body.replace(b'</body>', f'{css}</body>'.encode("utf8"))
res.init_headers()
Expand Down