How to pre-complie css style sheets in rails 2.3? - css

I have developed a new requirement for my client, I had added some css rule to an existing style-sheet file and these changes were reflecting on my local machine during development. But when I moved the changes to an staging server and restarted nginx all my functionalites are working but my css rules are not getting applied, when I checked the firebug console that particular file is getting included but my new css rules are not in there, should I pre-compile my css style-sheets if so how to do it in rails 2.3.x ...?
Thanks in advance.

Rails 2.3 does not have asset pipeline. So there is no need to precompile assets. Your assets should already be located in the Rails.root/public/stylesheets folder
Anything in Rails.root/public/ folder is served by the web server directly and it does not involve rails.
Your problem is most likely some sort of caching. You can try fetching the stylesheet directly using its URL like this
http://server.domain/stylesheets/mystyles.css
and see if your changes are reflected.
You can also check your Firebug -> Net tab to see if the style sheet is being downloaded from the server (http return code: 200 OK) or it is being picked up from the cache (http return code: 304 Not Modified)
There are ways to handle this type of issues, which rails 3.1 asset pipeline incorporates.
Using a different file name when content changes
Using the ETag header
Appending a unique hash (calculated using timestamp of the file) as a query string. For example http://domain/style.css?djfhsfhkkjdsfh where djfhsfhkkjdsfh will change every time style.css is modified.
are couple of commonly used tricks.
If you are keen on using asset pipeline with rails 2.3 you have options such as Jammit

Related

Custom Domain not loading CSS (Azure)

The custom domain I've been using (which is already linked to an App Service in Microsoft Azure Portal) is not loading the my current styles files (.css files). Actually, it's loading older versions of those files, which I didn't create (they've had been created previously by another employee).
Has someone experienced this same issue? If I go to the website created by the App Service, the .CSS loaded there is correct (the one I've created), but whenever I go to the custom domain linked with this website, the .CSS loaded is older.
Clearing the browser cache will work locally. However, other repeat visitors will have the same issue you are having. A global method would be to rename your CSS file. That will force the browser for repeat visitor's to load the new/ current CSS file.
ex. "style.css" --> "styles.css"
Rename the CSS file and don't forget to rename the meta link as well.
Try clearing browser cache memory. CSS files are often get cached in the browsers.

Laravel app serving resources that do not exist?

I am in the process of adding a Content Security Policy for a laravel application. While downloading external css and font styles to the local assets I have run into some odd template behavior.
I wanted to test that the paths to the newly downloaded libraries were correct, but when I change the name of files I downloaded and refresh, even with the browser cache disabled, it is still referencing the old location successfully. If you try to access the file in the old location directly by file path it fails (because it no longer exists).
Even more strangely, if I pull the code down to another computer and run it (I have not added the new libraries to git yet), the page still seems to think it correctly loaded that resource.
I tried clearing the following directories:
storage/framework/cache
storage/framework/sessions
storage/framework/views
and running the code again - on multiple computers, and it still reports that it is loading these files that are no longer there?
Does Laravel or commonly used front end frameworks with it store compiled templates somewhere else? I am completely perplexed...

Forcing Cache refresh after deploying new code

We are running into issue where our clients are served stale js, css files after code is deployed. We are using IIS as our webserver and our code is in ASP.Net 4.5. I did some research and figured out that ETag in conjunction with Cache-control should work. As I understand ETag is automatically generated by web server based on datetime stamp of file so I ran following steps to see why the system is not sending the latest version of js and css files.
Navigated to my website to a webpage let's call is demo.aspx.(Now assuming that demo.aspx contains reference to a.js, b.js and c.css)
Verified that a.js, b.js and c.css file were requested by browser and webserver delivered those files after I hard refersh a page(Ctrl + F5) on my website.
Clicked on some other webpage
Went to webserve and manually updated files (a.js, b.js and c.css to update datetime stamp of those files)
Navigated to demo.aspx again.
This time I see only request made to demo.aspx but not to any of the resource file (a.js, b.js and c.css).
I am at loss as to why .js files are not requested when I access my demo.aspx page.
Also, Is there any easy way to force client browsers to download latest version of .js and .css files every time I deploy code. Based on my research, I did find out that one way to do would be to rename .js and .css file. Please note that this soution won't work for us.
We do use update panel in our projects. Not sure if that has anything to do with browser not requesting js files second time
A widely used trick is to add a query string parameter that is incremented with every new version of the css or js file.
Like myScript.js?version=12. When the the number changes the browser sees it as a new file and it's downloaded rather than retrieved from cache.
Just changing the timestamp by editing the file won't work, the browser does not get the timestamp from the server. You can try this by saving an image or file from the website, they all have the timestamp of when they were being downloaded.

Rails: prevent a css file from being added to asset pipeline

We're accessing a 3rd-party iFrame (dialog) in our web app. This is loaded by javascript and served via the 3rd-party's server. If we provide them with a link to a custom CSS file we can change the appearance of the dialog.
How, in the Rails pipeline, can we create this file and then provide the 3rd-party with a URL that will, hopefully, respect (read: use) our CDN?
Does the file belong in vendor/assets/stylesheets/? I'm pretty sure that becomes part of asset pipeline as well...
Thoughts?

The changes not updating on server

I have build MVC 5 application which works fine when running via VS. When I publish it to the server first time it also works. Now I have made few correction to my css file and publish whole project again but website still see the old css file. I have removed all files from the server and tried few more times but it is still the same. When I check the css file on the server, the changes are inside the file.
I think it is related to MVC bundling as when I check the source it says that is accessing different file which is not even located on the server:
<link href="/Content/cssmain?v=Ikj7NnMg3q9kTHR7ynWOJDQFGMZl3mtVMi_2EkOJxc41" rel="stylesheet"/>
How can I force VS to minificate my css file again?
I've tried cleaning, rebuilding but no luck
Edit:
My bundle set up look like below and all files are located on the server in Content folder.
bundles.Add(new StyleBundle("~/Content/cssmain").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/ilightbox.css",
"~/Content/bannerscollection_zoominout.css"));
Many thanks
I think it is related to MVC bundling as when I check the source it says that is accessing different file which is not even located on the server:
CDN location? External Css lib (yours or 3rd party)? unsure what you meant by "not located on server"?
Yup, it does (look like ASP.net Bundling in action) - check your Global.asax, App_Start/BundleConfig or _AppStart and see if the bundle configuration setup point to/reference the "correct" locations for your css (and or script).
Is it just you experiencing getting the old css file loaded? Or anyone who views the site?

Resources