Bootstrap’s javascript works locally but not when deployed to a server

Bootstrap’s javascript works locally but not when deployed to a server

I downloaded the barebone example of Twitter’s bootstrap and customized it. I tested it locally (with WAMP server) and everything works perfectly, both the CSS and the JScript.
I uploaded the files to my webhosting service and the JScript just doesn’t work. I noticed it because dropdown boxes stopped working.
I searched and found other persons with the same problem but they all are using ruby and I’m not. Just the play CSS+JScript provided by bootstrap. Besides they said the solution was to include the bootstrap.js first and then the jquery.js. Well I tried it and it didn’t work, I even included the not minified .js and still it didn’t work.
I’m using the same browser (Chrome) for local and remote testing. I also tried different hosting services and the problem occurred in both.
Help is much appreciated.

Other similar questions:

Javascript features work on localhost but not when deployed to Heroku
twitter bootstrap drop down suddenly not working

Related:  Is left-aligning the button of a Twitter Bootstrap navbar possible?


Solution 1:

The issue might be that you load boostrap.js before jQuery. Locally your browser may be using a cached copy of Jquery, so it works there but not on your live site. Try fixing it by switching those two lines in your code:

<script src="/code4pt/styles/js/bootstrap.js"></script>
<script src="/code4pt/styles/js/jquery.js"></script>

Solution 2:

I know this is very strange but I think I got the solution. Previously I was using the (supplied) jQuery 1.7.2 minified. Now I changed it to use the jQuery 1.8.0 not minified. It just started to work… Another thing I did was to convert all files’ encoding to UTF8 (I think this was the real problem/solution)

Solution 3:

I had the same problem. In IE, the site was working on localhost but not when hosted on a different server. Adding the following meta tag fixed it.

<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 

Solution 4:

I was having simular issues before. The tabs function was working fine in my HTML site, but would not work when coded into a WordPress theme. All of the source URLS were being generated dynamically with WordPress’s .

Related:  How to create a Dynamic Bootstrap Multiselect

The tabs finally began working when I added all JS links (except for Modernizr into the footer instead of the header.

Solution 5:

Back to basics: If Debug is set to true on the local machine and false on the deployment environment as it should be, make sure your .min.js files are not overriding customizations you have made to the non-minified versions of .js files (applies to .css as well).

You can also turn Debug off on the local machine and you should see the same issues.

Solution 6:

I had the exact same problem, so was relieved to find this post and others like it. My resolution was similar. I pulled my hair out for half a day trying all different things. Walked the dog. Had half a dozen beers. Slept on it. Had breakfast. Recopied back the stylesheets at top, and the js from the bottom from the local html to the server php, and then for some unknown reason it started working again. The only points which seem useful for others going through the same:

  • Try and get back to a working scenario – in my case the index.html was working on the server but not the index.php. Getting these the exact same was key.
  • Try on different browsers just in case something strange is going on.
  • Make sure you keep clearing the browser cache (e.g. right click on the reload button in Chrome and choose ‘Empty Cache and Hard Reload’)
  • Inspect your bootstrap css and js versions. Change them forward and backward in version until you get success. Chances are, the version that came with your bootstrap theme download is the most likely one to work.
Related:  How to get the selected date value while using Bootstrap Datepicker?