Skip to content

jQuery files are getting included twice in the build #3063

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

Closed
umeshksingla opened this issue Aug 22, 2017 · 5 comments
Closed

jQuery files are getting included twice in the build #3063

umeshksingla opened this issue Aug 22, 2017 · 5 comments
Labels
Status: stale Issue will be considered inactive soon Support Support question

Comments

@umeshksingla
Copy link

Hi, I'm posting here because mailing lists and IRC are not really active, and will take it down as soon as I get to it.

I am trying to use some jQuery properties but most of them don't work, even simple things like $('#myModal').modal(); I get like $ is not defined or $().modal is not a function sometimes. Most of the queries got resolved by "You might be including jquery files twice, try removing one" solution on StackOverflow.

I checked the code after it builds and yes, it does have jQuery included twice but I still get $().modal is not a function. However, I succeeded in removing it from occurring it twice by having {% set script_files = [] %} in layout.html but then I get $ is not a function. Peeps, help me out here, how do I get to use jquery functions inside rtd/sphinx?

Funny thing is $.ajax() works. Below is the order of the relevant javascript files. Also, note that I am including my js file only after all the jquery and bootstrap javascript files.

The file used to solve the issue in case of conflict of jquery versions doesn't seem to work here, i.e. window.$jqTheme = jQuery.noConflict(true); <- this one.

....

<link rel="stylesheet" href="_static/bootstrap-sphinx.css" type="text/css">
<link rel="stylesheet" href="_static/pygments.css" type="text/css">
<link rel="stylesheet" href="https://media.readthedocs.org/css/badge_only.css" type="text/css">

<script type="text/javascript" async="" src="http://www.google-analytics.com/ga.js"></script>


<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>
<script type="text/javascript" src="https://media.readthedocs.org/javascript/doctools.js"></script>
<script type="text/javascript" src="https://media.readthedocs.org/javascript/readthedocs-doc-embed.js"></script>
<script type="text/javascript" src="_static/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="_static/js/jquery-fix.js"></script>
<script type="text/javascript" src="_static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="_static/bootstrap-sphinx.js"></script>

<link rel="shortcut icon" href="_static/favicon.ico">
<link rel="index" title="Index" href="genindex.html">
<link rel="search" title="Search" href="search.html">
<link rel="next" title="Getting Started Guide" href="getting-started-guide/index.html">

.....

@umeshksingla umeshksingla changed the title jQuery files are included twice in the build jQuery files are getting included twice in the build Aug 22, 2017
@stsewd stsewd added the Support Support question label Apr 16, 2018
@stsewd
Copy link
Member

stsewd commented Jun 25, 2018

Are you still having this problem? Please provide your rtd project url. I think rtd includes a minimal version of jQuery.

@stsewd stsewd added the Needed: more information A reply from issue author is required label Jun 25, 2018
@davidfischer
Copy link
Contributor

I definitely worked through some issues similar to this during some of the work on the RTD theme. I'm happy to investigate this if we get a bit more data and it is still an issue.

@umeshksingla
Copy link
Author

I haven't been working on it for a while but just checked, at least the issue is still relevant. My copy of the project is here: http://test-odl-docs.readthedocs.io/en/latest/ and the latest copy in production is here: https://docs.opendaylight.org/en/stable-oxygen/. It is only an issue when I try to add custom js/jquery scripts, though obvious, to the default rtd project.

@basnijholt
Copy link
Contributor

In #4787 (comment) I encountered the same problem. I fixed it by (copy from that issue):

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)

@stsewd stsewd removed the Needed: more information A reply from issue author is required label Oct 22, 2018
@stale
Copy link

stale bot commented Jan 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: stale Issue will be considered inactive soon label Jan 10, 2019
@stale stale bot closed this as completed Jan 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: stale Issue will be considered inactive soon Support Support question
Projects
None yet
Development

No branches or pull requests

4 participants