Is importing the same font multiple times from different sources harmful? - css

Problem:
In my HTML file, I have:
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
I want the font to be available to users who can't access fonts.googleapis.com but can access my website.
Solution I went with:
I provide a locally-hosted alternative by following the steps here in google-webfonts.helper. To be specific:
I've created a file roboto.css under my /assets folder and pasted the code in step 3 in the link above.
Downloaded the fonts under /assets/fonts.
Added to index.html: <link href="/assets/roboto.css" rel="stylesheet">
To confirm: I still have the initial google fonts. I.e., my index.html has:
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
<link href="/assets/roboto.css" rel="stylesheet">
Question(s):
(1) Is double-importing that way harmful in anyway?
(2) Is what I'm doing right?
(3) Is there a better way to achieve what I want?

Related

How to add a working link to external css file in .NET core 5 project

My project is here
(Look for "Laptop" branch, and "IsolatorUI" internal project)
I need to work with external css file I just saved in wwwroot/css.
I have a schtml Home view file and I would like to use it there.
So far, everything I tried did not work. Even using the site.css which was already there was unsuccessful.
Please ignore the different languague on cshtml HomeView file.
How can I establish a css file link? There are many discussions and suggestions I found on the internet, but none of them worked for me.
It's really frustrating when such simple thing doesn`t work...
Basically there is a disturbing bug with css in .NET framework files, but eventually this code worked for me:
In my View:
#section Styles {
<link href="#Url.Content("~/css/Home.css")" rel="stylesheet" type="text/css" />
}
And in my Layout:
<head>
...
<link rel="stylesheet" type="text/css" href="~/css/site.css" />
#RenderSection("Styles", false)
</head>

MIME type Error Django/React project on PythonAnywhere

I've used PythonAnywhere before, but this is the first project that utilizes a Django back end and React front end. What is strange is that if I run this exact project on localhost, there are no troubles at all. It is only when I host this website on PythonAnywhere do I get this error.
They're probably hard to see...
Refused to apply style from 'http://bluebirdteaching.pythonanywhere.com/static/css/2.8aa5a7f8.chunk.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Looking this up, I've come across this page a lot, but I just can't seem to make sense of the answers provided there. I just don't understand why this works on localhost, but not on PythonAnywhere.
I included the above image not just to show my index.html, but also to show the project directory as that seems to be necessary as the other post linked explains. If the answer I'm looking for is in that other post, I just can't make sense of it.
Again, everything works as expected when I run the project locally. Of course, thanks guys for any help. I've been going at this problem for a while now; any help/explanations would be a huge relief.
Edit: Here is the index.html file generated when I do npm run build. This is where all those chunk.css and chunk.js are referenced.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link rel="icon" href="/favicon.ico"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="theme-color" content="#000000"/>
<meta name="description" content="Web site created using create-react-app"/>
<link rel="apple-touch-icon" href="/logo192.png"/>
<link rel="manifest" href="/manifest.json"/>
<title>BlueBird Teaching</title>
<link href="/static/css/2.f3cffc9e.chunk.css" rel="stylesheet">
<link href="/static/css/main.aa904fbe.chunk.css" rel="stylesheet">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script>!function(e){function r(r){for(var n,a,p=r[0],l=r[1],f=r[2],c=0,s=[];c<p.length;c++)a=p[c],Object.prototype.hasOwnProperty.call(o,a)&&o[a]&&s.push(o[a][0]),o[a]=0;for(n in l)Object.prototype.hasOwnProperty.call(l,n)&&(e[n]=l[n]);for(i&&i(r);s.length;)s.shift()();return u.push.apply(u,f||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,p=1;p<t.length;p++){var l=t[p];0!==o[l]&&(n=!1)}n&&(u.splice(r--,1),e=a(a.s=t[0]))}return e}var n={},o={1:0},u=[];function a(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,a),t.l=!0,t.exports}a.m=e,a.c=n,a.d=function(e,r,t){a.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,r){if(1&r&&(e=a(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(a.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)a.d(t,n,function(r){return e[r]}.bind(null,n));return t},a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,"a",r),r},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},a.p="/";var p=this.webpackJsonpreactapp=this.webpackJsonpreactapp||[],l=p.push.bind(p);p.push=r,p=p.slice();for(var f=0;f<p.length;f++)r(p[f]);var i=l;t()}([])</script>
<script src="/static/js/2.f7026f3a.chunk.js"></script>
<script src="/static/js/main.f2b0e582.chunk.js"></script>
</body>
</html>
Solution
The reason why it was working locally but not on Heroku or PythonAnywhere was just because I needed to set out mapping for static files. Literally all I needed to do this whole time was python3 manage.py collectstatic.
One of the suggestions in the SO post you linked to is that you're may not actually be serving CSS, but may be serving HTML instead. Have you loaded the css page in a browser to see what you're returning from that URL?
The reason behind why it shows mime type error is that, staticfiles_dirs doesn't include src folder, and if there is images inside src, it doesn't get include in staticfiles folder while collectstatic process, hence throws error.
so make sure to not use import images inside src or public, instead host them.

My css and image files are being blocked and don't show in chrome

Chrome is blocking the css files and images from showing by generating this error in its console:
This request has been blocked; the content must be served over HTTPS
I have all my routes to the CSS files with relative paths:
<link type="text/css" rel="stylesheet" href="../resources/css/template.css"/>
<link type="text/css" rel="stylesheet" href="../resources/css/menu.css"/>
<link type="text/css" rel="stylesheet" href="../resources/css/general.css"/>
<link type="text/css" rel="stylesheet" href="../resources/css/system.css"/>
But there is a token (a token for maintaining the application state) added to the path (as this is ADF)
so chrome finds this:
'http://my.site.com/package/faces/resources/css/template.css?_adf.ctrl-state=q0l98h1nm_125'
I don't know how (I searched all my project and there's nothing that has a non-relative path)
I think, maybe the added token mixes it all for chrome?:
?_adf.ctrl-state=q0l98h1nm_125
Problem:
All the styles and images are blocked form the site, nothing shows, only letters (but in firefox shows it perfectly)
As you see in the html tags, all the css files I have have relative paths and I think that the browser should already decide to attach it the proper protocol, i.e the main protocol of the request.
Question:
How to resolve the problem?

CSS is missing when rendering an html page with codeigniter

I'm aware this is similar to numerous existing posts but after looking at a number of others I wasn't able to solve my problem. I'm attempting to load a folder full of html files I've been supplied with. I didn't write them but I have been modifying them to integrate them into an existing system.
I've tried three ways of opening them, with varying success:
1) Simply right click on 'index.html' and go 'open with' and select a browser. This works perfectly!
2) Place the whole folder contents, unchanged, onto my server under 'public_html/cat/html' and navigating to the url 'localhost/cat/html/index.html'. This returns a '404 page not found error'.
3) The strange one. Place the html files in the 'application/view' folder, separate the included css and javascript files and place them in existing folders 'public_html/css' and 'public_html/js' and update the links to them in the html files appropriately. These now look something like:
<link type="text/css" href="css/cat/style.css" rel="stylesheet" />
If I load this page by running a function that uses CodeIgniter's $this->load->view(...) function it finds the index file but loads it with no css and with broken links to the other pages. I've explored the page source and seen that the link is exactly as above but clicking gives an error that reads "404 Not Found...The requested URL /css/cat/style.css was not found on this server".
I've attempted to use the base_url() function (and site_url()) like this:
<link type="text/css" href="<? base_url('css/cat/style.css') ?>" rel="stylesheet" />
and it yields the same result on the surface but examining the page source reveals the link line has become:
<link type="text/css" href="" rel="stylesheet" />
which seems to be even worse!
Any hints?
Thanks for reading
Try the following:
<link type="text/css" href="<?php echo base_url('css/cat/style.css') ?>" rel="stylesheet" />
base_url() functon simply return value, you should take a care for displaying returned value to output! :-)
Have you correctly configure you config file in codeIgniter ?
Or shorthand
<link type="text/css" href="<?=base_url('css/cat/style.css') ?>" rel="stylesheet" />
Then view your page source and copy the link from there to your browser, see if you can access it.
Can try this code <link type="text/css" href="<?=base_url('css/cat/style.css');?>" rel="stylesheet" />
if it doesn't work, you could try <link type="text/css" href="<?=base_url('css/cat');?>/style.css" rel="stylesheet" />

How do I stop drupal from creating a different consolidated CSS file for every node type?

I have a fairly large Drupal 6 site with different modules enabled for different node/page types which is resulting in a different CSS file for each page type after the CSS has been consolidated. I understand the logic of not wanting to load css for every module, but is there a method for loading sitewide css into one file so that we can utilize the caching benefits of CSS?
Homepage:
<link type="text/css" rel="stylesheet" media="all" href="/site-files/example.com/files/css/css_1f2e88da1acf78556ee565984845d7cd.css" /></code>
Article:
<link type="text/css" rel="stylesheet" media="all" href="/site-files/example.com/files/css/css_1786ec41724511f6c0984222b790dca6.css" />
Category:
<link type="text/css" rel="stylesheet" media="all" href="/site-files/example.com/files/css/css_b7f516c6ab4921929598cfd377ce4523.css" />
Video:
<link type="text/css" rel="stylesheet" media="all" href="/site-files/example.com/files/css/css_a702453ef81af3318ad63a194280100e.css" />
There must be some logic in making these all one file when you consider that the difference between them is minimal.
Cheers, Steve
Answering my own question...
As always with Drupal, someone's already been there and done that, and here it is:
http://drupal.org/project/advagg
A little extra research into the benefits of first page load time vs a larger site side cached file, etc. has been very insightful.

Resources