Vulcanizing doesn't seem to be doing anything - polymer

I was under the impression that if I vulcanized my index.html, it would extract and concatenate my html imports. Here's a snippet from my index:
<!doctype html>
<html unresolved>
<head>
<base href="/">
<script src="/assets/traceur-runtime.js"></script>
<script src="/bower_components/webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="/bower_components/core-icon/core-icon.html">
<link rel="import" href="/bower_components/core-item/core-item.html">
<link rel="import" href="/bower_components/core-drawer-panel/core-drawer-panel.html">
<link rel="import" href="/bower_components/core-toolbar/core-toolbar.html">
and so forth. I am including just the polymer bits I need. I don't have any self-defined custom elements (I'm just assembling a UI from core- and paper- components).
I was under the impression that some combination of --inline and other flags would result in a very long index.html that no longer directly imported the bower_component files. I could be wrong about that, I suppose, but that's my goal. It's not that big of a deal; I am not even sure that the correct answer here is making my index.html huge in order to avoid 20 extra loads, especially with caching and all that. Still, there's no way to test this without having an inline version to test.
Edit:
I'm running vulcanize in the root of my built dist directory:
dist/
index.html
bower_components/
and it runs, I've tried with --inline and --csp and both, and it basically just spits index.html back out into vulcanized.html. If I do --strip, it strips whitespace, but that's it.

I have never tried to Vulcanize my Index.html, I always have an elements.html file which has all my imports and I finally import the elements.html in my Main file.
Whenever I try to Vulcanize my elements.html file it works as expected by concatenating all the Elements' definitions into one file for decreasing the number of http requests the browser has to make.
The problem might be that you are using the very latest version of Volcan which has been reworked on and the --csp feature has been moved to a standalone cli app by itself and the --strip has also be moved to the html-minifier app.
You might want to check that out.
https://github.com/PolymerLabs/crisper
https://github.com/kangax/html-minifier

Aha, I figured it out- I was using href="/bower_components/core-icon/core-icon.html" when I should have been using href="bower_components/core-icon/core-icon.html".
Note the lack of the leading slash. Now I just need to figure out how to wire it up so it can find bower_components properly.

Related

Stylesheet not loaded because of MIME type

I'm working on a website that uses Gulp.js to compile and browser sync to keep the browser synchronised with my changes.
The Gulp.js task compiles everything properly, but on the website, I'm unable to see any style, and the console shows this error message:
Refused to apply style from
'http://localhost:3000/assets/styles/custom-style.css' because its
MIME type ('text/html') is not a supported stylesheet MIME type, and
strict MIME checking is enabled.
Now, I don't really understand why this happens.
The HTML includes the file like this (which I am pretty sure is correct):
<link rel="stylesheet" type="text/css" href="assets/styles/custom-style.css"/>
And the style sheet is a merge between Bootstrap and Font Awesome styles for now (nothing custom yet).
The path is correct as well, as this is the folder structure:
index.html
assets
|-styles
|-custom-style.css
But I keep getting the error.
What could it be? Is this something (maybe a setting?) for gulp/browsersync maybe?
For Node.js applications, check your configuration:
app.use(express.static(__dirname + '/public'));
Notice that /public does not have a forward slash at the end, so you will need to include it in your href option of your HTML:
href="/css/style.css">
If you did include a forward slash (/public/) then you can just do href="css/style.css".
The issue, I think, was with a CSS library starting with comments.
While in development, I do not minify files and I don't remove comments. This meant that the stylesheet started with some comments, causing it to be seen as something different from CSS.
Removing the library and putting it into a vendor file (which is ALWAYS minified without comments) solved the issue.
Again, I'm not 100% sure this is a fix, but it's still a win for me as it works as expected now.
In most cases, this could be simply the CSS file path is wrong. So the web server returns status: 404 with some Not Found content payload of html type.
The browser follows this (wrong) path from <link rel="stylesheet" ...> tag with the intention of applying CSS styles. But the returned content type contradicts so that it logs an error.
This error can also come up when you're not referring to your CSS file properly.
For example, if your link tag is
<link rel="stylesheet" href="styles.css">
but your CSS file is named style.css (without the second s) then there is a good chance that you will see this error.
I had this error for a Bootstrap template.
<link href="starter-template.css" rel="stylesheet">
Then I removed the rel="stylesheet" from the link, i.e.:
<link href="starter-template.css">
And everything works fine. Try this if you are using Bootstrap templates.
I have changed my href to src. So from this:
<link rel="stylesheet" href="dist/photoswipe.css">
to this:
<link rel="stylesheet" src="dist/photoswipe.css">
It worked. I don't know why, but it did the job.
Make a folder just below/above the style.css file as per the Angular structure and provide a link like <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">.
Comments in your file will trip this. Some minifiers will not remove comments.
Also
If you use Node.js and set your static files using express such as:
app.use(express.static(__dirname + '/public'));
You need to properly address the files.
In my case both were the issue, so I prefixed my CSS links with "/css/styles.css".
Example:
<link type="text/css" rel="stylesheet" href='/css/styles.css">
This solution is perfect as the path is the main issue for CSS not getting rendering
In addition to using:
<base href="/">
Remove the rel="stylesheet" part from your CSS links:
<link type="text/css" href="assets/styles/custom-style.css"/>
I simply referenced the CSS file (an Angular theme in my case) in the styles section of my Angular 6 build configuration in angular.json:
This does not answer the question, but it might be a suitable workaround, as it was for me.
I know it might be out of context but linking a non existed file might cause this issue as it happened to me before.
<!-- bootstrap grid -->
<link rel="stylesheet" href="./css/bootstrap-grid.css" />
If this file does not exist you will face that issue.
The problem is that if you have a relative path, and you navigate to a nested page, that would resolve to the wrong path:
<link rel="stylesheet" href='./index.css'>
so the simple solution was to remove the . since mine is a single-page application.
Like this:
<link rel="stylesheet" href='/index.css'>
so it always resolves to /index.css
There are a lot of answers to this question but none of them seem to really work. If you remove rel="stylesheet" it will stop the errors but won't apply the stylesheets.
The real solution:
Just remove the .. It works then.
As mentioned solutions in this post, some of the solutions worked for me, but CSS does not apply on the page.
Simply, I just moved the "css" directory into the "Assest/" directory and everything works fine.
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="assets/css/site.css" >
I got the same issue and then I checked that I wrote:
<base href="./"> in index.html
Then I changed to
<base href="/">
And then it worked fine.
Also for others using Angular-CLI and publishing to a sub-folder on the webserver, check this answer:
When you're deploying to a non-root path within a domain, you'll need to manually update the <base href="/"> tag in your dist/index.html.
In this case, you will need to update to <base href="/sub-folder/">
https://github.com/angular/angular-cli/issues/1080
I had this problem with a site I knew worked online when I moved it to localhost and PhpStorm.
This worked fine online:
<link rel="stylesheet" href="/css/additional.css">
But for localhost I needed to get rid of the slash:
<link rel="stylesheet" href="css/additional.css">
So I am reinforcing a few answers provided here already - it is likely to be a path or spelling mistake rather than any complicated server setup problem. The error in the console is a red herring; the network tab needs to be checked for the 404 first.
Among the answers provided here are a few solutions that are not correct. The addition of type="text/html" or changing href to src is not the answer.
If you want to have all of the attributes so it validates on the pickiest of validators and your IDE then the media value should be provided and the rel should be stylesheet, e.g.:
<link rel="stylesheet" href="css/additional.css" type="text/css" media="all">
I have had the same problem.
If your project's structure is like the following tree:
index.html
assets
|-styles
|-custom-style.css
server
|- server.js
I recommend to add the following piece of code in server.js:
var path = require('path')
var express = require('express')
var app = express()
app.use('/assets', express.static(path.join(__dirname, "../assets")));
Note: Path is a built-in Node.js module, so it doesn't need to install this package via npm.
You can open the Google Chrome tools, select the network tab, reload your page and find the file request of the CSS and look for what it have inside the file.
Maybe you did something wrong when you merged the two libraries in your file, including some characters or headers not properly for CSS?
At times, this happens when the CSS file is not found. It's worth checking your base URL / path to the file.
Adding to a long list of answers, this issue also happened to me because I did not realize the path was wrong from a browser-sync point of view.
Given this simple folder structure:
package.json
app
|-index.html
|-styles
|-style.css
The href attribute inside <link> in file index.html has to be app/styles/style.css and not styles/style.css.
In case you are using Express.js without any JavaScript code, try with:
app.use(express.static('public'));
As an example, my CSS file is at public/stylesheets/app.css.
How I solved this.
For Node.js applications, you need to set your **public** folder configuration.
// Express js
app.use(express.static(__dirname + '/public'));
Otherwise, you need to do like href="public/css/style.css".
<link href="public/assets/css/custom.css">
<script src="public/assets/js/scripts.js"></script>
Note: It will work for http://localhost:3000/public/assets/css/custom.css. But couldn't work after build. You need to set app.use(express.static(__dirname + '/public')); for Express
For a Node.js application, just use this after importing all the required modules in your server file:
app.use(express.static("."));
express.static built-in middleware function in Express and this in your .html file: <link rel="stylesheet" href="style.css">
By going into my browsers console → Network → style.css ...clicked on it and it showed "cannot get /path/to/my/CSS", this told me my link was wrong.
I changed that to the path of my CSS file.
The original path before change was localhost:3000/Example/public/style.css. Changing it to localhost:3000/style.css solved it.
If you are serving the file from app.use(express.static(path.join(__dirname, "public"))); or app.use(express.static("public")); your server would pass "that folder" to the browser so adding a "/yourCssName.css" link in your browser solves it
By adding other routes in your browser CSS link, you'd be telling the browser to search for the css in route specified.
In summary: Check where your browser CSS link points to.
This is specific to TypeScript and Express.js
I Ctrl + F'd "TypeScript" and ".ts" and found nothing in these answers, so I'll add my solution here, since it was caused by (my inexperience with) TypeScript, and the solutions I've read don't explicit solve this particular issue.
The problem was that TypeScript was compiling my app.ts file into a JavaScript file in my project's dist directory, dist/app.js.
Here's my directory structure. See if you can spot the problem:
.
├── app.ts
├── dist
│   ├── app.js
│   ├── app.js.map
│   └── js
│   ├── dbclient.js
│   ├── dbclient.js.map
│   ├── mutators.js
│   └── mutators.js.map
├── public
│   ├── css
│   │   └── styles.css
├── tsconfig.json
├── tslint.json
└── views
├── index.hbs
└── results.hbs
My problem is that in app.ts, I was telling express to set my public directory as /public, which would be a valid path if Node.js actually were running TypeScript. But Node.js is running the compiled JavaScript, app.js, which is in the dist directory.
So having app.ts pretend it's dist/app.js solved my problem. Thus, I fixed the problem in app.ts by changing
app.use(e.static(path.join(__dirname, "/public")));
to
app.use(e.static(path.join(__dirname, "../public")));
https://github.com/froala/angular-froala/issues/170#issuecomment-386117678
Found the above solution of adding
href="/">
Just before the style tag in index.html
I was working with the React application and also had this error which led me here. This is what helped me.
Instead of adding <link> to the index.html, I added an import to the component where I need to use this style sheet:
import 'path/to/stylesheet.css';
In my case, when I was deploying the package live, I had it out of the public HTML folder. It was for a reason.
But apparently a strict MIME type check has been activated, and I am not too sure if it's on my side or by the company I am hosting with.
But as soon as I moved the styling folder in the same directory as the index.php file I stopped getting the error, and styling was activated perfectly.
Bootstrap styles not loading #3411
https://github.com/angular/angular-cli/issues/3411
I installed Bootstrap v. 3.3.7
npm install bootstrap --save
Then I added the needed script files to apps[0].scripts in the angular-cli.json file:
"scripts": [
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
// And the Bootstrap CSS to the apps[0].styles array
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.css"
],
I restarted ng serve
It worked for me.
If you are setting Styles in JavaScript as:
var cssLink = document.createElement("link");
cssLink.href = "./content.component.scss";
cssLink.rel = "stylesheet";
/* → */ cssLink.type = "html/css";
(iframe as HTMLIFrameElement).contentDocument.head.appendChild(cssLink);
Then just change field cssLint.type (denoted by the arrow in the above description) to "MIME":
cssLink.type = "MIME";
It will help you to get rid of the error.

Polymer - 404 Not Found

so I'm trying to write a simple hello world page using Polymer. The problem I'm having is whenever I run the #polymer serve command and load up my webpage it can't find the webcomponents.min.js and the iron-component-page.html. Any reason as to why this is happening and how can I fix it?
index.html
<!doctype html>
<html>
<head>
<title>polymer-element</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../iron-component-page/iron-component-page.html">
</head>
<body>
<iron-component-page src="polymer-element.html"></iron-component-page>
</body>
</html>
I tried some of the answers given here but still can't get it to work.
I haven't quite figured it yet but polymer is using polyserve under the hood, and I think that tries to be clever with url to file directory mapping. I think it assumes a directory structure where you are developing a re-usable component so after complete when your element also sits in bower_components, you go ../web-component/web-component.html to find the import, but your development structure has bower_components within the directory you are actually developing your component in.
When dealing with an app, I just put "bower_components" at the route of my app directory, and my elements in the "src" directory as a subdirectory of that. Then I explicitly use /bower_components/web-component/web-component.html in my html imports.
Running polymer serve from the root of your app then serves that at localhost:8080/
Short answer: Assuming your working dir is "x" and components are in "x/components" , create a soft link thus:
$ ln -s components bower_components
Long answer:
polymer serve does not seem to read/honor .bowerrc.
My components directory is "components" under which all my polymer components are present.
.bowerrc --> { "directory":"components"}
Running "polymer serve" starts the server, but when I navigate to "http://localhost:8000/index.html", I get a blank page.
Upon inspecting the network traffic in the browser, all requests to webcomponentjs* are returning 404s.
So.. polymer serve is not honoring a non-default components directory. It is expecting bower-components dir.

How to import GSS files into GWT HTML file

Using this guide: http://www.gwtproject.org/articles/gss_migration.html I converted all my CSS files to GSS. 2 of my CSS were loaded via the entry point HTML file index.html:
<link type="text/css" rel="stylesheet" href="main.css">
<link type="text/css" rel="stylesheet" href="gwt.css">
Now that those 2 files are GSS files, how do I include them in the project? I tried simply doing those 2 lines above with the GSS files, and while they do get loaded, some things don't work properly, such as custom styling on checkboxes.
Am I doing this right? I'd like those 2 files above to have access to GSS features, but I feel like this type of import only sees the files as CSS files with the wrong extension.
No, I think you missed some important things.
GSS is a compile step with optimization and dead "code" removal. The be able to do this, you will have to create a Bundle and a GssResource. You cannot include it in the HTML-file. All is done vie interfaces in your code.
In you linked gss migration file, there is a chapter "Prerequisites".
Take a look at the ClientBundle tutorial.

Bootstrap example pages not working

I am attempting to use Bootstrap; I am downloading example pages to build off of from the Bootstrap website. When I launch them, however, they look quite crummy in my Chrome browser.
For example, when I load the narrow-jumbotron page, the jumbotron spans the entire screen... What am I doing wrong? I have the css, js, and font folders inside the folder that I've saved the narrow-jumbotron.html page in.
Any help would be much appreciated.
Please check the source url or path of the css and other files. Possibly this is creating problem.
Firstly ensure that you have downloaded bootstrap.min.css and jumbotron-narrow.css.
Place them in the folder you are having the html file.
After that find the following 2 statements in your html file.
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">
Replace them with these lines:
<link href="bootstrap.min.css" rel="stylesheet">
<link href="jumbotron-narrow.css" rel="stylesheet">
It looks like it's probably is a path issue. When you download the original bootstrap framework, you'll have a /css and a /js directory. How your new html files get access to those places depends on where you put those directories. I'm going to assume you have some bootstrap test area. Let's just call this your main bootstrap area or core file area, whatever.
After you set that up, you probably went back for the other download which has the /examples directory buried within it. The files in there are set up to deal with being a few directory levels down. When you went into the /examples directory folder, did you copy over the whole /examples branch? Or just one set of the example files?
Let's try this just as one example just to try to get things working. Then once you get it working if you want to mess with directory / folder organization and file paths, that's fine.
Go find the examples/theme directory, wherever you put it. In this /theme directory rename index.html to theme.html
Take the theme.html and theme.css out of your /examples/theme directory and put them in the root directory of wherever you have your bootstrap's root index.html file. Now your file paths to CSS files and such should be set to match what the index.html file is doing.
Go into the theme.html file and look for the lines with the ../../dist/css/ as suggested earlier.
But make them look like this... "css/bootstrap-theme.min.css"
This should now have these files getting called from the correct places. This alone should work for you.
There's still one issue though. You'll see in the theme.html file a link to "../../assets/js/ie-emulation-modes-warning.js"
You could just ignore this, but to really have things all in order, you need to get that path right. So, go find your original download of the examples and get the whole /assets folder and sub-folders copied into wherever you have your bootstrap root; that is /assets should be at the same level as /css and /js.
Once again then, fix the link to look like this "assets/js/ie-emulation-modes-warning.js"
This will hopefully get you going and give you a clear and obvious sense of how the file paths work. If you like going forward, put things into better directory / folder structures and re-do the paths. Remember if you wanted to on a real web server, (local or remote), you can always use virtual paths from the root so you don't have to keep track of the levels everyplace for such files.
In any case, I did just test this and ideally it will work for you as well.
Just place bootstrap.min.css and bootstrap.min.js in the same folder as carousel folder for example.
Then fix the path of the js file to this:
<script src="bootstrap.min.js"></script>
And fix the path of the css file to this:
<link href="bootstrap.min.css" rel="stylesheet">
Try to delete "integrity" part
Instead of this:
<link href="css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
Make:
<link href="css/bootstrap.min.css" rel="stylesheet">
As integrity attribute checks whether code was changed.
That might help.
As of 2022 and the BootStrap version v5.2 the way to fix it is to copy paste the bootstrap.min.css file you get when you download the ready-to-use compiled code to the example folder you want it in and then change these lines from
<link href="../assets/dist/css/bootstrap.min.css" rel="stylesheet">
TO
<link href="bootstrap.min.css" rel="stylesheet">
This must do the trick

Relative paths not working under current Apache settings

I'm getting this strange behavior using relative paths on a directory with DirectoryIndex.
This is the directory structure:
/project/index.html
/project/css/main.css
/project/scripts/site.js
When I load the index.html file using this path:
www.mydomain.com/project/index.html
Everything loads just fine.
When I load like this:
www.mydomain.com/project/
First, the ending slash gets removed, second, the browser is looking for the CSS/JS at:
www.mydomain.com/css/main.css
www.mydomain.com/scripts/site.js
Which is obviously wrong.
I'm referencing the assets like this
<link rel="stylesheet" type="text/css" media="all" href="styles/main.css" />
I also tried adding "./" and same results.
Why is this happening? I'm still new to Apache configs so I'm not sure what I'm missing.
I don't want to use ../css/main.css to reference the assets because if somebody lands on the index.html file directly, then the assets won't load.
I'm pretty sure it's a dumb problem I'm over thinking.
Thanks.