Skip to content

Commit f19150a

Browse files
bmd3kdna2github
authored andcommitted
Change mimetype mapping of js files to 'text/javascript' (tensorflow#5747)
While investigating the test failure that lead to tensorflow#5746, we realized that RFC 9239 (https://www.rfc-editor.org/rfc/rfc9239) has changed the preferred js mimetype to 'text/javascript' from 'application/javascript'. To be a good citizen of the internet, this change modifies the logic introduced in tensorflow#3128 to force the mapping of js files to mimetype 'text/javascript'. We must also modify http_util.py to ensure that the proper charset is included in the Content-Type header. And, finally, we modify the example plugin to use 'text/javascript' as mimetype. To Test: * I ran local tensorboard and used the chrome developer tools to verify that the Content-Type for js files fetched by the browser was 'text/javascript; charset=utf-8'. I did a basic sanity test ensuring both Angular and Polymer portions of the application are running. * I ran a tensorboard with the example plugin installed and verified that index.js is returned with Content-Type 'text/javascript'.
1 parent 0ac66d4 commit f19150a

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

tensorboard/backend/http_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"text/css",
6464
"text/csv",
6565
"text/html",
66+
"text/javascript",
6667
"text/plain",
6768
"text/tab-separated-values",
6869
"text/x-protobuf",

tensorboard/examples/plugins/example_basic/tensorboard_plugin_example/plugin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ def _serve_js(self, request):
6262
filepath = os.path.join(os.path.dirname(__file__), "static", "index.js")
6363
with open(filepath) as infile:
6464
contents = infile.read()
65-
return werkzeug.Response(
66-
contents, content_type="application/javascript"
67-
)
65+
return werkzeug.Response(contents, content_type="text/javascript")
6866

6967
@wrappers.Request.application
7068
def _serve_tags(self, request):

tensorboard/program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def _fix_mime_types(self):
389389
"""
390390
# Known to be problematic when Visual Studio is installed:
391391
# <https://github.com/tensorflow/tensorboard/issues/3120>
392-
mimetypes.add_type("application/javascript", ".js")
392+
mimetypes.add_type("text/javascript", ".js")
393393
# Not known to be problematic, but used by TensorBoard:
394394
mimetypes.add_type("font/woff2", ".woff2")
395395
mimetypes.add_type("text/html", ".html")

0 commit comments

Comments
 (0)