Issues with JQuery and AWS S3 web hosting - javascript

I've created a website that uses 'http://code.jquery.com/jquery-latest.js' for some javascript animations. I've hosted my website on AWS S3, but it seems like the animations aren't working. I believe it has something to do with CORS and allowing it use the jquery link, but I may be wrong. Any advice? Sorry if I'm not using the terms correctly, am just learning all of this. Please let me know if theres more information required to answer, I'll gladly update the question with it.
I have this statement at the end of my html code.
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script src="assets/js/nav-main.js"></script>

Maybe your AWS S3 doesn't have access/permission to every link/Web from server, due to which jquery is not loaded. Download jquery file Download jquery and try using this downloaded file in code.

Related

Where to upload javascript file online and how to source it properly?

I'm trying to find how where and how to upload my scripts where I can source them as an external script.
I can't seem to find any question like this or maybe I'm not good enough in searching
But anyway, my situation is, I need to upload script online, a basic document.write to save space.
It cannot be a file on the same folder of storage as my pages because it's for work, and pages should be shareable to people as a standalone file so they don't have to extract it anymore.
Now I have tried to upload it online on different types of cloud or host, but I can't source it, because of security purposes I think?
Or maybe the source tag I should use must be different if it's online?
is it not <script type="text/javascript" src="https://abc.blabla.com/files/includes/html/page-links.js"></script>
Please please help. The main goal I have here is to upload my scripts online, and be able to source it as an external script on my "static and local website"
Thank you,
Renz
You probably are getting into to issues in most browsers when trying to load javascript from one domain (your-website.com) to another (localhost).
https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
You can try loading your browser with CORS disabled (Chrome):
Disable same origin policy in Chrome
Or with a plugin such as these:
https://chrome.google.com/webstore/search/cors
You can do static hosting in firebase. once you host the files there then you can use the file link in script tag.
<script src="https://test.firebaseapp.com/file.js" ></script>

How to use socket.io in a browser?

I'm trying to use socket.io for the browser. The problem is that I have no idea how to get it.
I'm following this tutorial (http://buildnewgames.com/real-time-multiplayer/) and there, they use <script src="/socket.io/socket.io.js"></script>. The problem is that this file doesn't exist and on the webiste of sockeit.io, there's no download for it.

I am trying to integrate Dropbox into my website. What does "curl" mean and how do I use it?

I went on the /list_folders method in the HTTP Developers guide (https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder) and it has "curl" as the example of how to use it. How do I put this in my HTML/JS code to pull in the folders? Thanks!
You can look at the reference for the JavaScript Dropbox library here which will guide you through creating a front-end website that utilizes the API. CURL is a very popular command line script used to transfer data over many supported protocols, but not something you can use from the browser.
More on the Dropbox API, this example Javascript script will show you how to list files.
The partial documentation can be found here.

How can I reload my js files when I restart my tomcat

When I update and reset my web project, client browser were unable get the newest js files.
So how to solve this problem.
I will appreciate that you can give me some advice
First, check your js file had updated in tomcat.
if the file is newest in tomcat.
The reason is the broswer cache.try to clear the brower cache.
If you use chrome,you can try this:
I usually use a chrome plugin to clear cache,The plugin named Clear Cache,you can find this plugin in chrome webstore.
or load js file like below
<script>
document.write("<script type='text/javascript' src='/js/test.js?"+Math.random();+"'></script>");
</script>

Use jQuery in HTML

In order to use jQuery, do I have to use the following reference in my html?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
What if my server does not have an internet connection?
Use this code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">window.jQuery || document.write('<script src="/res/jQuery/jquery-1.7.1.min.js"> \x3C/script>');</script>
This will try to download from the CDN, or otherwise use the local one. You must download the local one first though.
It will not work if you don't have internet connection.
To work locally you should copy jquery.js to your local directory and give relative path.
<script src="/jquery/1.5/jquery.min.js"></script>
It is not specifically for this case, but I think you should definitely understand how Client-server works. Also, you should understand what is Client-side scripting.
You would then understand that you (your browser) need to be connected to Internet in order to be able to reach the http://ajax.googleapis.com domain.
If you want to work with it locally, without ever reaching Internet, then download jQuery locally, and refer to it in your script tag.
Download the latest jquery file:
http://code.jquery.com/jquery-1.7.1.min.js
And save it to you project. It will now be available locally so you can reference it like this (only an example):
<script src="/path-to-your-jquery-file.js"></script>
It does not matter if your server has or has not connection to internet. Only the browser which tries to access page from said server need connection to internet. Server just needs to be "visible" from this browser in question.
It might be better, if you understood the basics of how internet works, before you start playing in developers.

Categories

Resources