14 replies [Last post]
Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 5 weeks 1 day ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2037
Points: 2256

Considering the usefulness of adding a CSS managment system in another thread. Here are the steps I've taken to implement it in ASP.NET MVC.

  1. Create a new MVC applictaion
  2. Open /Views/Shared/Site.Master
    1. <link href="/Css/Site.css" rel="stylesheet" type="text/css" />
    2. This doesn't point to anything yet

  3. Open Global.asax
    1. Add a MapRoute
      1. routes.MapRoute("Css", "Css/{cssFile}.css", new { controller = "Css", action = "Index", cssFile = "Site" });
      2. Now /Css/Site.css points to Css/Index

  4. Add a class Css.cs to Models
    1. Add public string Body { get; set; }
    2. Add public string Width { get; set; }
    3. Add public string Background { get; set; }

  5. Add definitions as desired
  6. Add a view for CssController/Index
    1. Make it strongly typed with CSScontrol.Models.Css as the model

  7. Change contenttype in page directive of Views/Css/Index.aspx to "text/css"
  8. That should do it.

I'm not sure that I'm convinced of the usefulness of this idea but it's possible and easy to implement in your ASP.NET MVC project.

I've attached a sample of the MVC2 project. Let me know if this is a good idea, a horrible idea or just a bit interesting.

I consider this a Triumph.

Tags:
Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 5 weeks 1 day ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2037
Points: 2256

Well the attached file didn't

Well the attached file didn't go through. If anyone wants to see it let me know and I'll post a link.

I consider this a Triumph.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 3 weeks 15 hours ago
London
Timezone: GMT+1
Joined: 2004-06-06
Posts: 15650
Points: 2788

I'd comment if any of that

I'd comment if any of that made sense, what language is that .nut? some sort of framework?

Course you realise real coders don't use frameworks it's cheating, but then again...

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 5 weeks 1 day ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2037
Points: 2256

Hugo wrote: I'd comment if

Hugo wrote:

I'd comment if any of that made sense, what language is that .nut? some sort of framework?

Course you realise real coders don't use frameworks it's cheating, but then again...

ASP.NET MVC (specifically MVC 2). I use C#. Besides, there's nothing wrong with cheating as much as possible. Tongue

I consider this a Triumph.

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 5 weeks 1 day ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2037
Points: 2256

I've added to the project to

I've added to the project to include compressing the CSS, or is it minifying? Basically, I just removed all the extra spaces, tabs, carriage returns/new lines, unneeded semicolons and comments. It brought a 4.96kb file down to 2.74kb.

I consider this a Triumph.

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 hour 3 min ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9190
Points: 3195

I'm not convinced that's

I'm not convinced that's worth the doing. Saving 2kB on a file that gets cached seems to be overkill. Download time saved is only ²⁄₇ seconds on dial up, and about ⅙ µsec on a fiber connection. If your traffic is measured in millions of visits, bandwidth savings may then be worthwhile. On the downside, bug chasing in served up pages is terribly difficult when such liberties are taken with the formatting.

cheers,

gary

Unplanned code results in a tangled wad of brain-cramping confusion.

There are enough html & css demos and tutorials to be interesting. Please visit.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 3 weeks 15 hours ago
London
Timezone: GMT+1
Joined: 2004-06-06
Posts: 15650
Points: 2788

Removed ALL semi colons?

Removed ALL semi colons? surely that's wrecked your stylesheet Smile

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 5 weeks 1 day ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2037
Points: 2256

gary.turner wrote: I'm not

gary.turner wrote:

I'm not convinced that's worth the doing. Saving 2kB on a file that gets cached seems to be overkill. Download time saved is only ²⁄₇ seconds on dial up, and about ⅙ µsec on a fiber connection. If your traffic is measured in millions of visits, bandwidth savings may then be worthwhile. On the downside, bug chasing in served up pages is terribly difficult when such liberties are taken with the formatting.

The formatting still exists and the CSS compression can be switched off. Right now it's just a setting in the configuration file but it could easily be made a checkbox on the backend. That said, I'm still not convinced that any part of this idea is worth doing. The whole thing could be a great waste of time. It's interesting though.

Hugo wrote:

Removed ALL semi colons? surely that's wrecked your stylesheet Smile

Unneeded, I meant, unneeded. Tongue Thanks. Smile

I consider this a Triumph.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 3 weeks 15 hours ago
London
Timezone: GMT+1
Joined: 2004-06-06
Posts: 15650
Points: 2788

Think you meant 'Superfluous'

Think you meant 'Superfluous' or perhaps 'Surplus' maybe 'Extraneous' or even 'Redundant', 'Expendable', my personal choice would have been 'Extrinsic'. So important to be exacting in these matters Big smile

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 5 weeks 1 day ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2037
Points: 2256

Hugo wrote: Think you meant

Hugo wrote:

Think you meant 'Superfluous' or perhaps 'Surplus' maybe 'Extraneous' or even 'Redundant', 'Expendable', my personal choice would have been 'Extrinsic'. So important to be exacting in these matters Big smile

You and your semantics. Tongue

I consider this a Triumph.

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 hour 3 min ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9190
Points: 3195

Quote: I just removed all the

Quote:

I just removed all the extra spaces, tabs, carriage returns/new lines,

That sure looks like destroyed formatting to me. Eh? Does Dresden come to mind?

cheers,

gary

Unplanned code results in a tangled wad of brain-cramping confusion.

There are enough html & css demos and tutorials to be interesting. Please visit.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 3 weeks 15 hours ago
London
Timezone: GMT+1
Joined: 2004-06-06
Posts: 15650
Points: 2788

gary.turner wrote: Quote: I

gary.turner wrote:
Quote:

I just removed all the extra spaces, tabs, carriage returns/new lines,

That sure looks like destroyed formatting to me. Eh? Does Dresden come to mind?

cheers,

gary

He's Bomber Harris re-incarnated Laughing out loud

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 5 weeks 1 day ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2037
Points: 2256

gary.turner wrote:Quote:I

gary.turner wrote:
Quote:

I just removed all the extra spaces, tabs, carriage returns/new lines,

That sure looks like destroyed formatting to me. Eh? Does Dresden come to mind?

The CSS file remains formatted. The Response.Filter will either serve it compressed or as is, depending on the value of a boolean variable, but the file remains unchanged on the development or production server.

I consider this a Triumph.

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 5 weeks 1 day ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2037
Points: 2256

Hmm. I really don't think

Hmm. I really don't think any of this is worth wasting the server's CPU cycles or memory to hold this in cache. It was fun but what's the point?

I consider this a Triumph.

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 5 weeks 1 day ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2037
Points: 2256

Another thought is the

Another thought is the browser will cache the file so OutputCaching isn't going to make that much difference except during simultaneous hits.

I consider this a Triumph.