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

  • SEARCH
  • Home
  • 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 7005761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:23:31+00:00 2026-05-27T21:23:31+00:00

Background: Got a C# project which involves a block of javascript that gets programmatically

  • 0

Background: Got a C# project which involves a block of javascript that gets programmatically injected in the web pages displayed by a webbrowser control. However, it is desirable to minify this block of javascript and have it embedded/written-into in a property of the resources-file. I know the minification of javascript is possible. I was just wondering if it’s also possible to write the resulting string into a specific property of the resources files using pre-build events.

P.S.: Of course the resulting string can be written into a file which is in turn bound to a resource-property. However I would prefer to avoid something as such, fearing the performance penalty it would impose in runtime (the javascript block gets loaded quite often). If I’m mistaken about this feel free to correct me.

  • 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-27T21:23:32+00:00Added an answer on May 27, 2026 at 9:23 pm

    For anyone struggling with similar issues out there, this is the step-by-step approach I have opted for (having run out of alternative solutions) in the context of Visual Studio 2010. The method below handles the minification of javascript files in a uniform way while respect the version control system you might use (by avoiding to generate phantom changes in files hosted by it). Here are the steps:

    1. Install Java and Google’s Closure (for javascript minification).

    2. Open the Resources of your project, go to file-resources and create a dummy file-property a-la foo.txt. This should create and include in your project the directory named Resources. You may delete the foo.txt file after this.

    3. Right click the Resources directory and create a javascript file ending in Uniminified.js (for example MyInjectableJavascript.Unminified.js). Edit the properties of this file and make sure that the build action is set to “None”. By the way, DO NOT reference this file in the resources.

    4. Now go back to the Resource’s file-properties and add a new file-property with the same base-name of the file created above only this time ending in min.js (for example MyInjectableJavascript.min.js).

    5. Go to the .min.js file that was created under the resources directory and turn it into an Embedded Resource.

    6. Now go the properties of your project -> build events and insert the following code:

    Pre-Build events (in one line):

    call "$(ProjectDir)JavascriptMinificationWithGoogleClosure.bat" "$(ProjectDir)Resources\MyInjectableJavascript.Unminified.js" "$(ProjectDir)Resources\MyInjectableJavascript.min.js"
    

    Post-Build events (two lines):

     del "$(ProjectDir)Resources\MyInjectableJavascript.min.js"
     call echo. 2> "$(ProjectDir)Resources\MyInjectableJavascript.min.js"
    

    What this does is that it minifies the javascript code before your project is built and after it is build it resets the minified file to a single newline.

    Note: The reason we don’t delete the minified file all together, is that visual studio will generate an error and will behave very weirdly if the minified file that is referenced by the resources is not found (in my case visual studio deleted Resources.Designer.cs completely out of the blue … 5 times). By truncating the min.js file it to a single newline you can keep it around and even add it to your version control system without bothering with it ever again.

    • Under the directory of your project place a file named JavascriptMinificationWithGoogleClosure.bat with the following contents:


      "%JAVA_HOME%jre6\bin\java" -jar "%CLOSURE_JS_HOME%compiler.jar" --js %1 --js_output_file %2

    • Finally, create two environment variables (Right click Computer -> Properties -> Enviroment Variables) named JAVA_HOME and CLOSURE_JS_HOME which point respectively to the directories you have installed the executables of Java and Closure. For example:


      JAVA_HOME -> C:\Program Files\Java\
      CLOSURE_JS_HOME -> C:\Program Files\Closure\

    Note: Make sure to include the trailing slash at the end of each of the two paths.

    • You can now access the minified javascript that will be generated during the build from C# code, using:


      Resources.MyInjectableJavascript_min

    Hope this helps. Good luck.

    Cheers,
    Dominick

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

Sidebar

Related Questions

I've got a big project written in PHP and Javascript. The problem is that
I've got a very simple project that tries to animate a UIView using block
I've got my Django project running well, and a separate background process which will
I've got an Android app which has a periodic background Service. I want this
I've got a script that changes the background colour of text that has been
I got a 9 patch image which is the background of some imageview on
What is UseCustomServer and UseCustomServerUrl in a ASP.NET Web Application Project? Some background: I
Background I'm at the planning stages of a DIY project that'll help me automate
I develop an app using PhoneGap. I got a service which is in background
I have a project which uses C++/CLI to implement a GUI and some background

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.