Loading a library from an URL versus local - html

When I load the library from an url, my code works as intended but when I try to load the same library from my local drive it spits out the error:
Uncaught ReferenceError: quat is not defined
at main (main.js:3)
at onload (index.html?_ijt=h48f9s7rceh7l34tfquh6ab8n5:7)
main # main.js:3
onload # index.html?_ijt=h48f9s7rceh7l34tfquh6ab8n5:7
What am I doing wrong in second case?
//index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body onload="main()">
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/gl-matrix/2.8.1/gl-matrix.js"></script>-->
<script src="Libraries/gl-matrix.js"></script>
<script src="main.js"></script>
</body>
</html>
//main.js
function main()
{
let x = quat.create();
console.log(x);
}

Your main.js file is loading before the main plugin script loading change the order like this.
<script src="Libraries/gl-matrix.js"></script>
<script src="main.js"></script>

first, please try changing the order of your <script> tags. Try loading the gl-matrix.js file first. Additionally you should make sure to provide either an absolute path to your local gl-matrix.js file or a path relative to the location of the file your <body>tags are located in.
Best Regards,
Bachkippe

Related

base-href in head of HTML seems to be ignored for all assets loaded

Maybe I just have this whole idea wrong, so lets check this out. I have the following HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<base href="/xyz">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<app-root></app-root>
<script src="runtime.js" defer=""></script><script src="polyfills.js" defer=""></script><script src="main.js" defer=""></script></body>
</html>
Now, when I try to load this in the browser with the following url: http://localhost:8080/xyz
it loads the index.html but for all the assets (styles and javascript files) I get 404
I would expect, because I have that base href="/xyz" that it would prefix all asset urls with that url, but as you can see it doesn't.
For completeness, here is my file structure:
./server.js
./xyz/index.html
styles.css
.....
So the server is serving all the files from the /xyz path
Relative paths are resolved by taking the base URL (http://localhost:8080/xyz), removing everything after the last / in the path (giving you http://localhost:8080/) and then appending the new path (http://localhost:8080/styles.css).
If you want /xyz/styles.css then you need to put a / on the end of your base path: <base href="/xyz/">

React.js (Reference Error: React is not defined)

I've attached copies of the code below. Only two files in my project now, app.js and index.html. When I go to google developers' tool and console, the log statement isn't going through. When I type react or react-dom into console I am told Reference Error: React is not defined. This is what a Udemy tutorial has told me to do last updated 5/19 so this should work. I have tried putting import React from "react"; in the top of the files but that doesn't work either. Any suggestions?
//app.js
console.log("App.js is running!)
//index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Indecision App</title>
</head>
<body>
<script src="https://unpkg.com/react#16.0.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom#16.0.0/umd/react-dom.development.js"></script>
<script src="/scripts/app.js"></script>
</body>
</html>
Looks like you'll need to also specify the crossorigin attribute on the scripts as per the react CDN-links docs.
<script crossorigin src="https://unpkg.com/react#16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom#16/umd/react-dom.development.js"></script>

Installing Jasmine failing

I'm trying to get Jasmine to work on my website. This is my HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner v2.1.3</title>
<link rel="stylesheet" type="text/css" href="/Content/css/jasmine.css" />
<script src="/Scripts/UnitTesting/boot.js"></script>
<script src="/Scripts/UnitTesting/jasmine-html.js"></script>
<script src="/Scripts/UnitTesting/jasmine.js"></script>
<!-- include source files here... -->
<!-- include spec files here... -->
<script src="/Scripts/UnitTesting/HelloWorldSpec.js"></script>
</head>
<body>
</body>
</html>
And HelloWorldSpec.js:
function helloWorld() {
return "Hello world!";
}
describe("Hello world", function () {
it("says hello", function () {
expect(helloWorld()).toEqual("Hello world!");
});
});
When I load this page, I get:
ReferenceError: jasmineRequire is not defined
ReferenceError: describe is not defined
I thought I got the reference to the JS files wrong. But when I look at the page source, and click on one of the js links, for example, "/Scripts/UnitTesting/boot.js", I see the source code, so it appears the files are loaded succesfully. What's going wrong here?
The boot.js file should be loaded after jasmine.js and jasmine-html.js Otherwise what would it boot? The correct order that you should include the files is:
jasmine.js
jasmine-html.js
boot.js
http://jasmine.github.io/2.0/boot.html
Starting with version 2.0, this file “boots” Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project’s specs. This file should be loaded after jasmine.js and jasmine_html.js, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.

How to assign webcontent path to load resources

I am getting 404 error while load css in my code
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>-------------</title>
<link type="text/css" rel="stylesheet" href="../../resources/css/hompage.css">
</head>
<body >
</body>
</html>
every time I am confusing and not able to load resources.
How to target resource of eclipse to load in browser. I have doubt href="../../resources/css/hompage.css path only plese find attachement.
Try move your css file, or if IDE support it, use absolute path, like /css/*

Scripts not being called

I am using ExpressJS. My scripts or CSS will not load.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<title>Customer Info</title>
<link rel="stylesheet" href="/stylesheets/testing.css" type="text/css" media="screen" charset="utf-8"/>
<script type="text/javascript" src="/javascripts/jquery-1.9.1.js"></script>
<script src="/javascripts/jquery-ui-1.10.2.custom.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="/javascripts/testing.js"></script>
</head>
<body>
//body contents
</body>
</html>
I know the problem is not with the location. When I render this EJS view in express none of the scripts are loading. I can not understand why it would work for an almost identical view, but not this one. Any ideas?
Step 1
In your node.js file locate the part where you configure the express.
It would be like.
var express = require('express')
, app = express();
app.configure(function() {
//configure the express codes go here
}
in that check out the line of code where you configure the folder which serves the static files. like images,css, and js. I would be like.
app.use(express.static(__dirname + '/public'));
here in the above case public should be exactly the name of the parent folder which holds the stylesheets and javascripts folder that you mentioned in the above html.
like
--app.js
--package.json
--views/
--node_modules/
--public/
--stylesheets/
--testing.css
--javascripts/
--jquery-1.9.1.js
--jquery-ui-1.10.2.custom.js
--testing.js
Step 2
If the above is configured correctly then you can make sure
app.use(express.static(__dirname + '/public'));
in config comes ahead of
app.use(app.router);
so that you can make assure that your line is not ignored by a 404 route handler you written in the router.
Step 3
You can inspect the rendered page with Firebug or Chrome inspector and check in the networks tab what was the response you received for the js and css files you have mentioned.
As per you question it should be 404 file not found and if its something else you should update it in the question.
Step 4
If you still cant fix the issue then you have to update the question with the node.js codes you are using. So that we could look into it.
i believe it is that "/" in start of every src line which is not making it load. for example .. use them this way
<link rel="stylesheet" href="stylesheets/testing.css" type="text/css" media="screen" charset="utf-8"/>
<script type="text/javascript" src="javascripts/jquery-1.9.1.js"></script>
<script src="javascripts/jquery-ui-1.10.2.custom.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="javascripts/testing.js"></script>
well, these scripts and css files are in their respective folders and to reference to them, you just have to start the source from its name directly, e-g src="folder/script.css"
This was if folders are one level above from html file. for example
your index.html file is in folder1
your style.css file is in folder1 >> css
your script.js file is in folder1 >> scripts
then for this level, above suggestion will 100% work. If other types of levels are there, e-g
index.html is in folder1 >> folder2 >> index.html
style.css is in folder1 >> css
script.js is in folder1 >> js
then your src should look like
<link rel="stylesheet" href="./stylesheets/testing.css" type="text/css" media="screen" charset="utf-8"/>
<script type="text/javascript" src="./javascripts/jquery-1.9.1.js"></script>
<script src="./javascripts/jquery-ui-1.10.2.custom.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="./javascripts/testing.js"></script>
please note a "." dot in start. It means the code will reference the file from one folder behind. if the file is 2 folders behind, then use it two times, e-g ././folder1/css
hope that helps
You have to set expressJS to to use static links linking your assets or public folder that contain js and css folders.
express.static(__dirname + '/assets', { maxAge: 24*60*60*1000 }
Then use dots at the beginning of href links or simply add server url instead. e.g. :
<link rel="stylesheet" href="../css/test.css" type="text/css" >