Cannot see changes in Magento 2 js and css - magento

I am new to magento 2 and I am creating extension for it.
But I am unable to see any js and css changes.
When i check on my source code my js file custom.js and css file custom.css is loaded properly but i am unable to see any of my changes.
I tried to clear cache and didn't get any result.
I cleared cache from backed and manually as well and disabled all
cache too.

step 1.
rm -rf pub/static/frontend/*
step 2.
rm -rf var/cache/*
step 3.
php bin/magento s:s:d -f
step 4.
php bin/magento indexer:reindex
The above step worked for me. I hope it will work for you also.

step 1. delete all folders under pub/static/frontend
step 2. delete cache folder under var/cache
Now open your command prompt and go to your root installation of magento 2
and fire the following commands
step 3. php bin/magento setup:static-content:deploy
step 4. php bin/magento indexer:reindex
The above step worked for me. I hope it will work for you also.
Let me know if you still facing any problem.

To work efficient it is possible to use the following command to do all tasks together:
rm -rf var/view_preprocessed; rm -rf pub/static/frontend/*; rm -rf var/cache/*; php bin/magento setup:static-content:deploy -f de_DE;

Even if Magento is in Dev mode, Nginx may set caching headers on Javascript and CSS files:
$ bin/magento deploy:mode:show
Current application mode: developer. (Note: Environment variables may override this value.)
See that Note? And sure enough:
$ curl -v 'https://foo.local/static/version51/adminhtml/Magento/backend/en_US/Dc_Foo/js/foo.js'
< HTTP/1.1 200 OK
< Server: nginx/1.21.6
< Date: Tue, 12 Jul 2022 12:00:07 GMT
< Content-Type: application/javascript; charset=utf-8
< Content-Length: 1082
< Last-Modified: Tue, 12 Jul 2022 05:57:18 GMT
< Connection: keep-alive
< ETag: "62cd0d3e-43a"
< Expires: Wed, 12 Jul 2023 12:00:07 GMT
< Cache-Control: max-age=31536000
< Cache-Control: public
< X-Frame-Options: SAMEORIGIN
< Accept-Ranges: bytes
Note the Expires header, set for one year in the future (answer written July 2022).
You can configure Nginx or Apache or any other server to not serve these headers, but my preferred method is to configure my browser to ignore caching when development tools are in use. In Chrome that can be accomplished by opening DevTools (F12), then clicking on the gear icon (⚙), then checking Preferences -> Network -> Disable cache while DevTools is open.

It may be because a core CSS rule has a priority over your css rule for the same DOM element. You should check it with a browser developer tools.

Require JS will cache the changes to your javascript files (even in developer mode). To disable caching, add the below to MyNamespace/MyModule/view/frontend/requirejs-config.js
var config = {
urlArgs: "bust=" + (new Date()).getTime()
};

Related

How disable XAMPP or PHP caching?

After I reinstalled XAMPP and copied the projects folder into htdocs and ran the script to create the database I have a rare case of cache. This is something that I have done on other occasions without problems.
Regardless of the changes you make to the code, a previous version is always displayed without the changes.
I clean the browser cache... no changes. I ruled out that the problem was in the browser, because I used two other browsers where I had never opened the page and the version showed is the same without the changes.
In PHP I have the headers to avoid the cache:
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); // HTTP/1.1
header('Pragma: no-cache');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
In httpd.conf I commented the line of:
LoadModule cache_module modules/mod_cache.so
Without success... I installed an older version of XAMPP and the problem remains.
Some suggestion, please??
Regards

I am getting 404 error for css and js files after I installed magento

I installed magento 2.4.2 on bluehost vps hosting, but I am getting the website as shown in figure 1 I tried every solution I found online but non of them worked for me.
Solutions I tried:
1- changing the permission for pub/static dir.
2- In app/etc/di.xml, find the virtualType name=”developerMaterialization” section and its item called name=”view_preprocessed”. I changed Symlink with Copy in Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink.
3- php bin/magento setup:static-content:deploy -f command
4- RewriteEngine On, in /pub/static/.htaccess file
5- set sign static files to No (dev/static/sign to 0)
I wish someone can help
Hi #Silverwolf96 and welcome on StackOverflow.
There are few things you can try/check.
1.) Check in the page source if the URLs to your files are correct. If not set correctly, set them manually as described in step 2.
2.) Go to Store > Configuration > General > Web and set under Base URLs & Base URLs (Secure) your URLs for static files - you can set this URL manually and it needs to be set as http://www.example.com/static/
3.) You can try to remove pub/static/frontend on the server
4.) Check what happens if you select Magento Luma as the default theme

Issue with the Http Status in the template Blanco. Magento

I have installed the template Blanco in Magento 1.7.02 and I receive a “200 OK” status from the server, despite the URL still being invalid and the 404 page still being presented.
[root#host.shopmami.com] ~ >> curl -I http://www.almohadaspremama.com/aa
HTTP/1.1 200 OK
I disable the template Blanco and obtain the correct status.
root#host.shopmami.com] ~ >> curl -I http://www.almohadaspremama.com/aa
HTTP/1.1 404 Not Found
Please, anybody could help me to find the issue in the template?

Publishing site created with Laravel error

Hi there i follow this tutorial how to setup on the FreeWebHostingArea com :
If your domain is pointed to public_html directory then all content should placed in that directory. How ? let me tell you
Copy all files and folders ( including public folder ) in public html
Copy all content of public folder and paste it in document root ( i.e.
public_html ) Remove the public folder Open your bootstrap/paths.php
and then changed 'public' => DIR.'/../public', into 'public' =>
DIR.'/..',
and finally in index.php,
Change
require DIR.'/../bootstrap/autoload.php';
$app = require_once DIR.'/../bootstrap/start.php'; into
require DIR.'/bootstrap/autoload.php';
$app = require_once DIR.'/bootstrap/start.php';
but when i load the index i get this error
Fatal error: require(): Failed opening required
'/home/vhosts/epernikhardware.eu5.org/vendor/composer/autoload_files.php'
(include_path='/home/vhosts/epernikhardware.eu5.org/vendor/phpseclib/phpseclib/phpseclib:.:/usr/share/pear:/usr/share/php')
in
/home/vhosts/epernikhardware.eu5.org/vendor/composer/autoload_real.php
on line 47
And can amy one explain me how to easily get this simple site to work is it so hard to publish a few web pages with laravel framework. Please help
I don't know about that hosting but for other hosting service such as JustHost, GoDaddy, BlueHost, HostGator... I deploy the Laravel web pretty much easy.
1) Access to the host via SSH, get the source code
$ cd www/
$ git clone https://github.com/ME/MY-PROJECT.git .
2) Get Composer:
$ curl -sS https://getcomposer.org/installer | php -- --filename=composer
3) Update all dependencies (/vendor)
$ composer update
4) Move the /public/.htaccess to the root
$ mv public/.htaccess .
That's all, site is ready. Perhaps, there are more steps in configuring the database but it is not necessary to mention here.
If you host your site on Forge or DigitalOcean, the process would be much easy, just add the source origin, and most of things will be done automatically.
Make sure the PHP version in your computer and the PHP version in the cpanel of your hosting site is the same. I also had the same problem and this helped me.

session problems on mamp

I have a problem with sessions, my php code works perfectly on easyPhp but not on MAMP.
With easyPhp I have to modify the php.ini file from session.auto_start = 0 to session.auto_start = 1.
What should I do to make it work with MAMP?
For MAMP, the default php.ini setting is session.auto_start = 0. So I'm assuming you wish to modify it to session.auto_start = 1 as you did for easyPHP.
In order to do so, follow these steps:
Start MAMP
File > Edit Template > PHP > [select php.ini file]*
Find the line that says: session.auto_start = 0
Change it to session.auto_start = 1
Save the file
Restart your MAMP server
Once you change any of the MAMP configuration defaults, MAMP will generate an appropriate configuration file in the following subdirectory: ~/Library/Application\ Support/appsolute/MAMP\ PRO/templates/, so you can edit those files directly, instead of going through MAMP.
* The php.ini file you select should match the version you're running through MAMP (selected under server > PHP, in the main window).

Resources