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

prevent jQuery from being loaded twice #4787

Closed
basnijholt opened this issue Oct 21, 2018 · 3 comments
Closed

prevent jQuery from being loaded twice #4787

basnijholt opened this issue Oct 21, 2018 · 3 comments

Comments

@basnijholt
Copy link
Contributor

basnijholt commented Oct 21, 2018

Details

Expected Result

We have to load jQuery in the <head> (to show interactive plots) which is what we do by having this in our conf.py, a custom layout.html, and an empty _static/jquery.js file that gets loaded at the bottom by default (to prevent loading jquery a second time).

Actual Result

We overwrite the default jquery.js, which works in local builds. However, on readthedocs it uses another jquery file.

Html of our locally build docs:

        <script type="text/javascript" src="../_static/jquery.js"></script>
        <script type="text/javascript" src="../_static/underscore.js"></script>
        <script type="text/javascript" src="../_static/doctools.js"></script>

Readthedocs source html:

        <script type="text/javascript" src="https://media.readthedocs.org/javascript/jquery/jquery-2.0.3.min.js"></script>
        <script type="text/javascript" src="https://media.readthedocs.org/javascript/jquery/jquery-migrate-1.2.1.min.js"></script>
        <script type="text/javascript" src="https://media.readthedocs.org/javascript/underscore.js"></script>

Because of this ipywidgets are not displayed on adaptive.readthedocs.io.

How can I change this behavior?

Related: qt/adaptive/issues/118

@stsewd
Copy link
Member

stsewd commented Oct 21, 2018

Maybe related to #3063 and #4367 (comment)

@basnijholt
Copy link
Contributor Author

I fixed this issue using this commit python-adaptive/adaptive@6cdd24e.

Basically I added this code to my conf.py:

def remove_jquery_and_underscore(app):
    # We need to remove the jquery and underscore file that are
    # added by default because we already add it in the <head> tag.
    remove = lambda x: not any(js in x for js in ['jquery', 'underscore'])
    if hasattr(app.builder, 'script_files'):
        app.builder.script_files = [x for x in app.builder.script_files
                                    if remove(x)]

def setup(app):
    app.connect('builder-inited', remove_jquery_and_underscore)

@basnijholt
Copy link
Contributor Author

This above solution fixed our problem, but I really consider it a hack.

The proper solution is in readthedocs/sphinx_rtd_theme#545.

I will close this issue now. @stsewd thanks for the prompt reply! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants