Skip to content

Commit

Permalink
Render the script tag inside the body element instead of after it
Browse files Browse the repository at this point in the history
  • Loading branch information
href committed May 3, 2017
1 parent ab76914 commit 2f9c42a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
@@ -1,6 +1,13 @@
Changelog
---------

- Render the script tag inside the body element instead of after it.

This turns the output into valid HTML. Rendering it outside the body element
as it was done before works in practice, but it is technically not
valid.
[href]

0.3.3 (2016-10-04)
~~~~~~~~~~~~~~~~~~~

Expand Down
6 changes: 4 additions & 2 deletions README.rst
Expand Up @@ -73,8 +73,10 @@ This will result in the following html (formatted for readability):

<html>
<head></head>
<body>hello</body>
<script type="text/javascript" src="./assets/jquery.bundle.js?1234"></script>
<body>
hello
<script type="text/javascript" src="./assets/jquery.bundle.js?1234"></script>
</body>
</html>

For it to work you need an 'assets/js' folder with a 'jquery.js' file in the
Expand Down
2 changes: 1 addition & 1 deletion more/webassets/tests/test_webassets.py
Expand Up @@ -150,7 +150,7 @@ def test_inject_webassets(tempdir):
# md5 hash of the javascript files included
injected_html = (
'<script type="text/javascript" '
'src="/assets/common.bundle.js?ddc71aa3"></script></html>')
'src="/assets/common.bundle.js?ddc71aa3"></script></body>')

assert injected_html in client.get('?bundle=common').text

Expand Down
2 changes: 1 addition & 1 deletion more/webassets/tweens.py
Expand Up @@ -104,7 +104,7 @@ def __call__(self, request):

if scripts:
response.body = response.body.replace(
b'</html>', scripts.encode('utf-8') + b'</html>', 1
b'</body>', scripts.encode('utf-8') + b'</body>', 1
)

if stylesheets:
Expand Down

0 comments on commit 2f9c42a

Please sign in to comment.