If a CSS rule changes, does the browser need to be refreshed - html

If I have changed a CSS rule via javascript, do I need to do anything to "refresh" the browser to redisplay the current page using the updated rules?

No--a refresh isn't necessary--and if it did occur it would restore the document to its original state.
The change should take place immediately (setting display: none, for example). Use FireFox plugin FireBug (http://getfirebug.com/) or the IE Developer Toolbar (built into IE8 and available as a free plugin for previous versions) to dynamically view the HTML to ensure the change you think is taking place is actually occurring.

Changing CSS properties on the fly via JavaScript should automatically make the change in the user's web browser unless there is something wrong with your script of if the user has JavaScript turned off.

Related

how to display modified webpage without clearing cache

My website is hosted by blue host.
Whenever I modify/add text in the HTML and I refresh my webpage, the change would be reflected.
However, when I update the css file, i must clear my chrome brower cache in order to reflect the change.
This is painful as I need to constantly clear my cache. Sometimes tweaking format takes several such clearing.
Is there any way i could avoid clearing the cache but still reflect the css related changes?
You have three options:
-reload the page with cntr+shft+R
-add a dummy Parameter to your css file which you change when you need to refresh the css. E.g. .../yourpath/css.css?v=1
(In case you can use scripts such as PHP, you can use a random value for this parameter which will automatically force the css-reloading on each page refresh)
-open the developer console (F12) and disable the cache on the network tab.

CSS not updating on change

When I try and change my current CSS or add new CSS to my style-sheet no change shows up (tags are still being styled by the old unchanged code).
For example, if I delete the contents of a class and I go into chrome debug tool using F12, I can see that the contents which I deleted are still showing up - even if I clear the cache by pressing Ctrl+Shift+R, OR by pressing Ctrl+F5!
All the other files of my website seem to be updating correctly, so if I use inline styles it will update correctly.
Strangely when I go into my websites control panel and manually download the CSS style-sheet from my server I can see that the code has indeed being updated with the new code, this is weird because upon inspecting it with F12, I can still see the old code with no changes.
I am using Microsoft Webmatrix to do my coding.
I am using the Chrome Web browser.
I am using Hostgator hosting.
I've exhausted all my trouble shooting options and have been beat by something that by all means should not occur. I think I've had a problem like this before and I think that it was solved by just waiting a day for whatever magic to work but I shouldn't have to wait. A problem like this is absolutely unacceptable in a live environment. Any ideas of what could be causing this?
FIXED!
changed: https://example.com/app/source/css/main.css
to this: https://example.com/app/source/css/main.css?v=1
You could try ctrl + shift + r (on a PC) to hard reset the browser and make sure the cache isn't displaying old CSS.
One thing is to verify you are editing the correct file. I managed to have that issue one time when I had two files named the same, but one was outside the folder with the index.html and that was the one I was editing.
Add ?v=1 behind the URL of the CSS link in the head, which will force using a non-cached version, because of the different (new) file name. The number should be unique, so if you want to use this in the future, make sure to replace the 1.

How do I get Chrome to cache my HTML/CSS changes?

My web application makes changes to the CSS dynamically with Javascript, in response to user input. When the user navigates away from the updated page, then hits BACK, it reloads the page from the disk cache but the CSS changes are gone. So the page looks like it did before the user input.
Is this normal? Is there a way to get Chrome to cache the updated HTML that includes my CSS changes?
This is not related with Chrome. If CSS rule is changed by end user input (with JavaScript CSS operation) and nothing else is done, these CSS rule update (the latest CSS rules) is stored in browser memory, which is cleaned when page refreshes.
To make these updated-CSS "cached", you need to make it persistent by store it in LocalStorage (browser side) or Database in server.

Chrome inspector doesn't show css line number anymore in many of the localhost sites

Every other website I visit, the inspector works as expected:
But in many of the sites I'm editing within apache server (using xampp) somehow they doesn't show the "filename.css:lineNumber" data
Also, every change I try to do in the inspector in thse sites, doesn't do anything to the code shown in the source tab.
I've tried refreshing, hard refreshing with cache, closing and opening the tab, closing and opening chrome again. The same problem occurs.
In other sites the inspector works well, but not in many of the localhost sites.
Has someone experienced this before? Is there a way to fix this?
If you are using a client-side CSS generator library such as Lea Verou's excellent -prefix-free or client-side Less, you will not see source information as it has all been processed and reinjected as style elements.
Client-side Less has a property [dumpLineNumbers] to include source line info as a comment in the generated source. (I'm not sure if this will display in Chrome's inspector - but I think it might)
The only "fix" I know of for -prefix-free is to temporarily remove it, obtain the source info for reference, then put it back in.
I have had the exact same problem (not using a css generator), and it appears to be a known bug with the current version of Chrome, the solution is to use the more up to date Beta version known as Chrome Canary - Here's the link :)
https://www.google.co.uk/intl/en/chrome/browser/canary.html
Try to check what the format of your CSS file is. I had the same trouble with the UNIX and Macintosh formats. For example, try to open you CSS file in Notepad++ and in the bottom right corner of the window you'll see your current format. If you see UNIX or Macintosh there, click it with the right button of your mouse and change to DOS/Windows. Then save your file and refresh your page in Chrome. It definitely helped in my case.enter image description here

How to edit raw HTML with Greasemonkey/Tampermonkey before it is parsed by browser

Does greasemonkey or tampermonkey have functionality that lets me edit the raw HTML response before it gets passed to the browser?
I'm trying to do this in an attempt to modify an inline script before it executes. This solution must work on both Firefox and Chrome so something like beforescriptexecute won't work because chrome doesn't support it yet.
If not, is there an extension that does provide this functionality that is available to both browsers?
Quick answer: No.
Longer answer: Tampermonkey and Greasemonkey operate on editing the page has loaded, not at any time prior to that. So, preventing a script from executing isn't going to happen. Neither of these tools can change the code before it's run, it only alters once it has run and can inject certain scripts into the page after it's loaded that affect the data displayed or the appearance. The best you could do is update or replace what's displayed based on the inline script, but it's still going to get sent initially.