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

前端 未结 9 1451
刺人心
刺人心 2020-12-15 18:56

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 JScr

相关标签:
9条回答
  • 2020-12-15 19:26

    Late to the party but I found out that my issue was that the Bootstrap.js was not being pushed out during deployment.

    0 讨论(0)
  • 2020-12-15 19:31

    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.
    0 讨论(0)
  • 2020-12-15 19:32

    I ran into this on a site I built and uploaded to Amazon S3. Worked fine on my local machine and even my local server, but didn't work when served from Amazon. The console in Firefox (but not Chrome) showed it was failing to load bootstrap.min.css (et. al) because their MIME type was not text/css.

    I had to use the S3 console to force change their types to text/css, clear caches, and reload. Voila!

    0 讨论(0)
  • 2020-12-15 19:33

    In addition to the very useful suggestions by @dialex and @Darrell , I will add that if none of that works, you can review any code that you might be linking to, ie. via require ('page.php');, for duplicates. Duplicated .js links tend to cause these issues.

    0 讨论(0)
  • 2020-12-15 19:35

    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)

    0 讨论(0)
  • 2020-12-15 19:38

    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>
    
    0 讨论(0)
提交回复
热议问题