Let's say that I've done a good bit of update to my css files on my dev machine (with my browser set to ignore the cache, no always seeing updates right away).
In this question and other places, I've seen the approach of adding a version number to the links:
<link type="text/css" href={% static "/path/mystyles.css?version=2" %} rel="stylesheet">,
which is fine, but on the dev machine, I get an error in the console, and the file isn't found:
GET http://127.0.0.1:8000/path/mystyles.css%3Fversion%3D2 net::ERR_ABORTED 404 (Not Found)
I've read that perhaps collectstatic will fix it on the dev side, but there's an ominous-looking warning:
You have requested to collect static files at the destination
location as specified in your settings:
/patttthhhhh/static
This will overwrite existing files!
Are you sure you want to do this?
What will happen when I run collectstatic? Where will it get files from to overwrite those?
The recommended way would be to use something like django-compressor (usage) or the likes to process your CSS into a single file and then bake a hash into the filename or dir. So that way your asset would become /mystyles.beb23fe.css.
What ended up working easily was changing the format of the version tag:
<link type="text/css" href="{% static '/path/mystyle.css' %}?version=2" rel="stylesheet">
instead of:
<link type="text/css" href={% static "/path/mystyles.css?version=2" %} rel="stylesheet">
Is fine in dev and production.
Related
I'm writing a program using laravel. To manage css and js, I used versioning and call it with a function like this
<link rel="stylesheet" href="{{ mix('/css/app.css') }}">
The code above produces html output as follows
<link rel="stylesheet" href="/css/app.css?id=53a226b301fc510ddf79">
When I upload to hosting, why does the above code only produce html like this ?
<link rel="stylesheet" href="/css/app.css"> (the mix-manifest.json / id file not load)
this is my localhost
and this is on the hosting
Did you run npm run dev after deploy it on your hosting?
Make sure in your webpack.mix.js have .version() method.
I think in your localhost your laravel run in development mode. And in the hosting the laravel run with production mode. Check your .env file.
I'm using symfony 5 and I have no idea where can I pu my css, js, images files.
I read many posts about it but none helped me...
I tried:
composer require symfony/asset
symfony console assets:install
Here is the way i am using asset function in my twig files:
<link rel="stylesheet" type="text/css" href="{{ asset('css/base.css') }}">
And yes I have a file at public/css/base.css...
But when I inspect the result page, my line is replaced by:
<link rel="stylesheet" type="text/css" href="/css/base.css">
Did someone have any idea ?
Best regards,
If you're NOT using webpack (or webpack encore), your assets should be in your public folder which is the root of your public project. For example, if you have a file called style.css in public/css/style.css, you can access it in your browser with the url (assuming you use a local server started in the public dir) http://localhost:8000/css/style.css.
The Symfony asset component goal is to guess if your project is in a subdirectory and therefore to resolve the correct path. In order to use it in a Twig template with the previous imaginary file :
<link rel="stylesheet" href="{{ asset('css/style.css') }}">
The asset function will be able to produce the right path for your file.
If you're using webpack, the setup is a bit harder so if you don't I won't explain it here.
I am trying to load CSS file in localhost but it's just showing white page. I was try to drag and drop file direct to browser and its opened. So file its not empty. and file also open when i use a server and add link to file.
I am using laravel 5.8, PHP 7.2
<link href="{{ URL::asset('css/style.css') }}" rel="stylesheet" type="text/css" media="all" />
CSS file location /public/css i am getting link in source http://localhost/css/style.css
This is most likely a file reference error. Check the markup output and compare the file URL against where it actually sits in the directory structure. If they match up, maybe a directory permissions issue?
In css links only asset is working fine... No need to include URL. so try using only asset.
Is there a way to configure jekyll so that when it builds the static files in the _site folder it adjusts all the assets/urls so it works in a subfolder?
My setup is like this:
www.example.com/
I pushed all the _site files/folders to a subdirectory:
www.example.com/blog/
So now when I view my site, all the css/images are not rendering as they are all pointing to :
<link rel="stylesheet" href="/assets/vendor/bootstrap/css/bootstrap.min.css">
But the correct URL should be:
/blog/assets/vendor/bootstrap/css/bootstrap.min.css
I am using nginx for this, and I created a location section like:
location ^~ /blog/ {
alias /home/deploy/apps/_site/;
}
Have you tried using the baseurl setting in Jekyll? When hosting a project on GH it is basically serving out of a sub folder like you are trying to do, baseurl is the common way to deal with it.
In your config file set the baseurl:
baseurl: /blog
then update your templates to use Jekyll's relative_url filter to pull in the baseurl setting properly. For example:
<link rel="stylesheet" href="{{ 'assets/css/site.css' | relative_url }}">
or elsewhere
{{ page.url | relative_url }}
A less robust solution is to prepend all the urls with {{ site.baseurl }} directly like:
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/site.css">
There are various ways to build the url with the baseurl - these are just a couple of them.
If your site is already done and none of your links have baseurl built into them, there is no easy way to add it in other than going and updating all the links.
That said, there is not a lot of magic to baseurl - other than making it one place to edit it if it ever needed to be changed. That and there is something about jekyll serve that helps the site work in the browser better when doing local dev work (serve and build treat baseurl slightly differently I believe).
this is a newbie question for you guys.
In file
/home/myhome/apache-tomcat-6.0.29/webapps/view/test.jsp
I have <link rel="stylesheet" type="text/css" href="WEB-INF/resources/view.css"/>
and the view.css file is located at
/home/myhome/apache-tomcat-6.0.29/webapps/view/WEB-INF/resources/view.css
For some reason, it's not loading the css file. But when I put the css file in the same directory as the jsp page and change href accordingly, it worked. What did I do wrong in my attempt to load the file from another folder?
Thanks alot.
try
Firebug, to debug if path is correctly loaded or not. As i can see it issue with path so you have to debug.
http://www.ehow.com/how_2221659_debug-css-firebug.html
But you can try with this line instead
<link rel="stylesheet" type="text/css" href="/view/WEB-INF/resources/view.css" />
Since I am using tomcat, I guess tomcat just won't let a page access anything in the WEB-INF folder, I moved the file else where not in WEB-INF, it worked...