Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 214
dialex Avatar asked Aug 27 '12 09:08

dialex


4 Answers

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>
like image 93
Hoff Avatar answered Oct 30 '22 01:10

Hoff


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)

like image 22
dialex Avatar answered Oct 30 '22 00:10

dialex


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" /> 
like image 43
Shahed Avatar answered Oct 30 '22 01:10

Shahed


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.
like image 36
Darrell Avatar answered Oct 29 '22 23:10

Darrell