Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 436797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:30:50+00:00 2026-05-12T20:30:50+00:00

Using VS2008 and ASP.NET 3.5 (or VS 2010 / .NET 4.0?), how can I

  • 0

Using VS2008 and ASP.NET 3.5 (or VS 2010 / .NET 4.0?), how can I include a bit of dynamic ASP.NET server-side code in mostly-static JavaScript and CSS files?

I want to do this to avoid cloning entire JS or CSS files to vary just a small part of them multi-tenant sites. Later, I want to extend the solution to handle localization inside javascript/CSS, dynamic debugging/tracing support, and other cool things you can get by injecting stuff dynamically into JavaScript and CSS.

The hard part is that I don’t want to lose all the cool things you get with static files, for example:

  • JS/CSS code coloring and intellisense
  • CSS-class “go to definition” support in the IDE
  • automatic HTTP caching headers based on date of underlying file
  • automatic compression by IIS

The server-side goodness of static files (e.g. headers/compression) can be faked via an HttpHandler, but retaining IDE goodness (intellisense/coloring/etc) has me stumped.

An ideal solution would meet the following requirements:

  1. VS IDE provides JS/CSS intellisense and code coloring. Giving up server-code intellisense is OK since server code is usually simple in these files.
  2. “go to defintion” still works for CSS classes (just like in static CSS files)
  3. send HTTP caching headers, varying by modified date of the underlying file.
  4. support HTTP compression like other static files
  5. support <%= %> and <script runat=server> code blocks
  6. URL paths (at least the ones that HTTP clients see) end with .JS or .CSS (not .ASPX). Optionally, I can use querystring or PathInfo to parameterize (e.g. choosing a locale), although in most cases I’ll use vdirs for this. Caching should vary for different querystrings.

So far the best (hacky) solution I’ve come up with is this:

  • Switch the underlying CSS or JS files to be .ASPX files (e.g. foo.css.aspx or foo.js.aspx). Embed the underlying static content in a STYLE element (for CSS) or a SCRIPT element (for JS). This enables JS/CSS intellisense as well as allowing inline or runat=server code blocks.
  • Write an HttpHandler which:
    • looks at the URL and adds .aspx to know the right underlying ASPX to call
    • uses System.Net.HttpWebRequest to call that URL
    • strips out the containing STYLE or SCRIPT tags, leaving only the CSS or JS
    • adds the appropriate headers (caching, content type, etc.)
    • compresses the response if the client suports compression
  • Map *.CSS and *.JS to my handler.
  • (if IIS6) Ensure .JS and .CSS file extensions are mapped to ASP.NET

I’m already using a modified version of Darick_c’s HttpCompression Module which handles almost all of above for me, so modifying it to support the solution above won’t be too hard.

But my solution is hacky. I was wondering if anyone has a more lightweight approach for this problem which doesn’t lose Visual Studio’s static-file goodness.

I know I can also hack up a client-side-only solution where I split all JS and CSS into “vary” and “won’t vary” files, but there’s a performance and maintenance overhead to this kind of solution that I’d like to avoid. I really want a server-side solution here so I can maintain one file on the server, not N+1 files.

I’ve not tried VS10/.NET 4.0 yet, but I’m open to a Dev10/.net4 solution if that’s the best way to make this scenario work.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:30:51+00:00Added an answer on May 12, 2026 at 8:30 pm

    I have handled a similar problem by having a master page output a dynamic generated JSON object in the footer of each page.

    I needed to have my js popup login dialog box support localization. So using JSON.NET for serialization, I created a public key/value collection property of the master page that pages could access in order place key/values into such as phrase key/localized phrase pairs. The master page then renders a dynamic JSON object that holds these values so that static js files could reference these dynamic values.

    For the js login box I have the masterpage set the localized values. This made sense because the masterpage also includes the login.js file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently using vs2008 with asp.net mvc framework for web development. Im missing a
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
I am using VS2008 + C# + .Net 3.5 + IIS 7.0 + ASP.Net
I've created an asp.net website with VS2008, how can I publish it in VS2008?
Hi I am using vs2008 making an asp.net.vb app. The following stored procedure resolutely
I am using VS2008 for ASP.NET apps. My Solution Explorer has hierarchy like this:
I have asp.net MVC2 application. I am using VS2008 and want to hook up
I have an ASP.NET website that worked fine using and debugging in VS2008. I
I have a arraylist in my web application project in asp.net/C#/VS2008 and I'm using
(Was: ASP.Net codebehind not finding controls on the web page) I'm using VS 2008.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.