I have ran into an issue when using ejs to link external stylesheets and script tags. Here is my link for my stylesheet.
<link rel="stylesheet" href="styles/index.css">
When I highlight the link to the sheet and follow it (in VScode) I am brought to the correct file. I know it is going to the correct location for sure.
However, when I run this on my localhost:5000 I get an error. Here is what the error reads.
Refused to apply style from 'http://localhost:5000/styles/index.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
I notice this is pointing to my localhost:5000/styles/index.css, but I do not want it to point to my local host, I want it to point to the directories I have set up in my file structure.
Does anyone know how to resolve this?
Thank you so much for your time.
if u are trying to use ejs in a nodejs project with express ,u should first define a folder that contain all the static files like css and images then give permission to the browser to get this file .check this:
https://expressjs.com/en/starter/static-files.html
Related
If there is any documentation on this topic on the Node-Red website, please let me know.
I am building a static website (HTML/JS/CSS) with Node-Red. I use HTTP GET nodes to call my Javascript and CSS files. I connect my Javascript through the tag, and this works well. I can connect my CSS file through the . When I visit that css_http response (which is linked to my Node-Red server), I can see the CSS file. However, all of my HTML files are ignoring the CSS files.
On the console, I get a "CSS was ignored due to mime type mismatch" warning, but I can access the CSS file through HTTP, and I double-checked to make sure my syntax was correct.
I currently load a single CSS file through the payload, and this works, but the code still looks messy in the console.
Is there any way I can link my external CSS file through a Node without using the payload (using the tag would be ideal)? Should I have my external CSS file in an HTML outside of the server? Why does it work for my JavaScript files but not my CSS ones?
As the error points out you are sending a CSS file with the wrong mime type.
"CSS was ignored due to mime type mismatch"
You can set the mime type with the "Content-Type" header in the http-response node.
I have the following error on all my JS files:
The script from “http://localhost:8086/home/js/classie.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.
I made the project using Intelij and TomCat web server, the code for the scripts inside HTML5 looks like this:
<script type="text/javascript" src="js/script-delete-word.js"></script>
Why is this happening even thought I put type="text/javascript inside the script tag? The same problem is for the .css files too, I tried to change the location of js and css folder, but it didn't worked.
I made the project using Intelij
Your IDE isn't really relevant (unless you are using some sort of built-in web server that comes with it: if you are you should make that explicit in the question).
Why is this happening
Something is wrong with your HTTP server. You haven't said what server you are using (or provided the code for it if you've written it yourself).
Why is this happening even thought I put type="text/javascript inside the script tag?
The type attribute (when given a MIME type, the module value is a special case) tells the browser what to expect to get in the response to a request for the script's URL. This lets the browser avoid requesting scripts in programming languages it doesn't understand. The HTTP response headers are still authorative.
I have stucture code like this:
I try to load javascript into php file like this:
But i have an error like this:
This is my html :
And this is another javascript:
And i try to copy paste the link, and i got an error 404 not found. How can i fix it? Thanks.
Permissions
When the host is correct, and the file is in the right place, and you have no other networking problems, you may sometimes still get a 404 because of bad file permissions. If a server does not have permission to access a file, it may send out a 404 error in response. The reason why some "Not Authorized" error is not given instead, is that this would reveal more information about the files than you, the owner of the server, may intend. The way to respond to requests for privileged files without revealing whether or not they exist is to give a 404.
On Windows, you can view and change the permissions from the File Explorer by right-clicking on the file or folder, then going to Properties -> Security -> Edit. For more information, see the notes on permissions on Microsoft's site.
File Types
Besides permissions, a server must also be configured to serve the type of file you are accessing. If files with different extensions are served, but .js files are not, check the configuration of your server to make sure that .js files aren't blacklisted (or not whitelisted, as the case may be).
Directory Location
You should also verify that the files are actually stored in the top-most directory of the web server if that's how you are accessing them. If they aren't, you may need to prefix the path with the path from the webserver root to your application directory. E.g., instead of fusioncharts/..., you may need /path/to/fusioncharts/... or ../../path/to/fusioncharts.
Other Considerations
In your particular case, you should also verify that the files inside the fusioncharts folder are actually structured the way you think. (E.g., is there really a js/[insert name here].js file inside the fusioncharts folder?
If none of that solves your problem, try to take something that is working and gradually make it more and more similar to the files that aren't working. By figuring out at which point you go from a working setup to a not working setup, you may discover the problem.
If you are referring to a file with path: /ui/new-file.js
then,
1.In html file include
<script type="text/javascript" src="/ui/new-file.js"></script>
2.In server.js or app.js whichever you have, include
app.get('/ui/new-file.js', function (req, res) {
res.sendFile(path.join(__dirname, 'ui', 'login-file.js'));
});
Assuming you are using codeigniter, you can use base_url() function to include JS files in your codeignitor view template file.
<script src="<?php echo base_url(); ?>fusioncharts/js/fusioncharts.js" type="text/javascript"></script>
codeigniter default view template is called welcome_message.php and this file is located in application/view folder.
This is how I include js files in my codeigniter projects. Hope this will help.
In the html you can write *script** in the head or in the body, but not in your file js, delete this in fusionCharts.js
<script type=text/javascript>
In fusionCharts.js write only the function without the script
If you are developing locally, try clearing your cache.
Google Chrome likes to use the cached JavaScript files instead of the real ones.
Clearing your cache should resolve the issue.
When I try to include less.js it gives me a XmlHttpRequest Exception 101.
I include the .less file like this:
<link rel="stylesheet/less" type="text/css" href="anything.less" />
Now, I'm working on a Tumblr theme, and this ONLY happens when I upload the theme to Tumblr.
Both files are included correctly, I can reach the real files by clicking the links in the source code.
Can anyone help me with this one?
I used this for production only. It's very time consuming to compile the less file locally, embed it into the template and then upload it again.
Not a duplicate of:
LESS CSS minimal setup failure
I'm using Safari, and I'm using a global url (http://somelink.com/style.less).
You said:
The html file is then on www.tumblr.com, and the .less file is on
themelandia.com
This means that less.js file must make a cross domain ajax request in order to retrieve your .less file. Browsers do not allow this, and thus the request fails.
If you want to fix your problem, you must put the .less file somewhere on tumblr.com
New to ASP and probably never named a Javascript file ".inc" :-)
But that seems to be the norm where I'm currently working.
I observed that right on the first page I started getting these javascript errors
Message: 'globalVariableXXX' is undefined
I found that the javascript file wasn't getting called at all.
Just changed the name to ".js" and it worked !!
The ASP file includes the JavaScript file like this :
<SCRIPT LANGUAGE="Javascript" SRC="include/MenuCode.inc"></SCRIPT>
But there are 100's of these ".inc" files and 100's of references to them, hence don't want to go with this solution.
I'd rather understand it..
Any idea why it would've worked in the first place and why it isn't now ?
I'm sure I'm missing something pretty basic in ASP..
Another point : This application is installed on another server and it works just fine there when I hit it. I'm trying to install it on this new box.
Where I made the change for it to work:
In IIS, Right click on the name of the machine and the Mime Types are right over there. Checked the old server and it had the settings for ".inc", copied them and it started working :) Thanks all.
Maybe someone changed the webserver to prevent it serving .inc files ?
In the management console (inetmgr) right click the website and choose Properties. Go to "home directory" tab and click Configuration.
You will probably see the .inc extension there (in the mapping tab) meaning those files are parsed by the ASP engine.
Remove the item from the mappings table, apply and you should be able to parse those files as raw data.
The proper way to use a script tag for javascript is with the type attribute, such as
<script type="text/javascript" src="include/MenuCode.inc"></script>
see: http://www.w3schools.com/tags/tag_script.asp
language isn't even listed as a supported attribute by the standard..
Edit: The reason .js worked and .inc didn't is .js is in the mime type definitions of the server as a JAVASCRIPT mime type by default. If not using an extension configured as text/javascript by default, you have to tell the browser what to treat the file as somehow. This is why the text attribute of script is a required attribute as per html 4.01.