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 8498111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:18:49+00:00 2026-06-11T00:18:49+00:00

I’m looking into Google’s stylesheet renaming feature and I’m not sure how to rewrite

  • 0

I’m looking into Google’s stylesheet renaming feature and I’m not sure how to rewrite my jquery selectors. I didn’t find the doc very clear on that.

If I have some code that looks like this:

<div class="MyClass"></div>
<div id="MyID"></div>

$('.MyClass').someFunc();
$('#MyID').someFunc();

How must the HTML and javascript be written so that CSS renaming will work?

Thanks for your suggestions.

  • 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-06-11T00:18:50+00:00Added an answer on June 11, 2026 at 12:18 am

    For Closure-stylesheets to work in combination with an external library like jQuery, you will need to use the Closure-library as well to add support for goog.getCssName. However, because Closure-Library is written to make maximum use of the dead code elimination of Closure-compiler, only a very small amount of the library code will be included in the final output (about 1KB in this example).

    Step 1 – Setup your project

    You’ll need the following tools:

    • Closure Library
    • Closure Compiler
    • Closure Templates
    • Closure Stylesheets

    Step 2 – Setup Your Source Files

    Stylesheet Source (sample.gss)

    @def BG_COLOR              rgb(235, 239, 249);
    
    @def DIALOG_BORDER_COLOR   rgb(107, 144, 218);
    @def DIALOG_BG_COLOR       BG_COLOR;
    
    .MyClass {
      background-color: BG_COLOR;
      height:100px;
    }
    
    #MyId {
      background-color: DIALOG_BG_COLOR;
      border: 1px solid DIALOG_BORDER_COLOR;
      height:100px;
    }
    

    Closure Template Source (sample.soy)

    {namespace ClosureSample}
    
    /**
     * SampleHtml
     */
    {template .SampleHtml autoescape="false"}
        <div class="{css MyClass}"></div>
    {/template}
    

    Javascript Source (sample.js)

    goog.require('ClosureSample');
    document.write(ClosureSample.SampleHtml());
    
    $(function() {
        $('.' + goog.getCssName('MyClass')).css('background-color', 'pink');
    });
    

    HTML Source (development.htm)

    <!DOCTYPE html>
    <html>
    <head>
      <title>Closure stylesheets with External Library</title>
      <link rel="Stylesheet" media="all" href="sample.css" />
      <script type="text/javascript" src="sample_renaming_map.js"></script>
      <script type="text/javascript" src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script>
      <script type="text/javascript">
        goog.require('goog.soy');
        goog.require('goog.string.StringBuffer');
      </script>
      <script type="text/javascript" src="soyutils_usegoog.js"></script>
      <script type="text/javascript" src="sample-templates.js"></script>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    </head>
    <body>
      <script type="text/javascript" src="sample.js"></script>
      <div id="MyId"></div>
    </body>
    </html>
    

    Step 3 – Compile your Stylesheet and Templates

    Using the tools downloaded from the templates and stylesheet projects, you’ll need to compile the sample.gss and sample.soy files. Here’s the commands used for this sample:

    java -jar closure-stylesheets.jar \
        --pretty-print \
        --output-file sample.css \
        --output-renaming-map-format CLOSURE_UNCOMPILED \
        --rename CLOSURE \
        --output-renaming-map sample_renaming_map.js \
        sample.gss
    
    java -jar SoyToJsSrcCompiler.jar \
        --shouldProvideRequireSoyNamespaces \
        --shouldGenerateJsdoc \
        --outputPathFormat {INPUT_FILE_NAME_NO_EXT}.js \
        --cssHandlingScheme goog \
        sample.soy
    

    With these files, you can test the renaming during development. See the example.

    Step 4 – Compile the Project for Production

    First recompile your stylesheets to produce a renaming map using the “CLOSURE_COMPILED” option:

    java -jar closure-stylesheets.jar \
        --output-file sample.css \
        --output-renaming-map-format CLOSURE_COMPILED \
        --rename CLOSURE \
        --output-renaming-map sample_renaming_map.js \
        sample.gss
    

    Then you will need to calculate the Closure-library dependency files and compile all of the source javascript files into a single source.

    Note: since jQuery is not compatible with ADVANCED_OPTIMIZATIONS of Closure-compiler, it will not be included as input. Instead, reference the appropriate jQuery extern file found in the Closure-compiler contrib/externs folder.

    The calcdeps.py script in the Closure-library project can be used to also call the Closure-compiler on the input files it determines.

    python calcdeps.py \
        -i sample.js \
        -p PATH_TO_CLOSURE_LIBRARY_FOLDER \
        -p sample-templates.js \
        -o compiled \
        -c compiler.jar \
        -f --js=sample_renaming_map.js
        -f --compilation_level=ADVANCED_OPTIMIZATIONS \
        -f --warning_level=VERBOSE \
        -f --externs=jquery-1.7-externs.js \
        -f --js_output_file=sample_compiled.js
    

    See the final result: compiled version.

    Final Notes

    As you can see, using Google Closure Stylesheets requires not only pieces of the entire Closure-tools suite, but is quite involved.

    • Outputing the HTML required use of Google Closure-templates. In this contrived example I used a document.write call to output the HTML with the properly renamed class, however there are more elegant and maintainable techniques for production code.
    • Closure-stylesheets does not rename ID selectors, therefore the code for an ID is not affected.
    • For ease of viewing, the compiled example references the jQuery library off of the Google CDN. However, it would be equally valid to concatenate the jQuery library and the compiled source into a single source JS file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from

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.