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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:15:58+00:00 2026-05-29T04:15:58+00:00

Background: I have a css and a js that is used only by the

  • 0

Background:

I have a css and a js that is used only by the Google maps template tag, that I include in my templates where-ever needed.

Inside template tag google_map:
...
...
return render_to_string('google_map.html', context)

Inside google_map.html I have the required css and the js :

<link rel="stylesheet" type="text/css" href="mystyle.css" />

My problem is :

I have a page with 3 maps, therefore 3 calls to the template tag. This implies the css and the js is included 3 times in the same page. [Should not happen]

Now, I can-not include these css and js in the header of the page, since all the pages are not having the maps so there, on all those pages it would be a burden.

What should I do, so that if a page has 3 or more maps, even then there is only a single include of the css & js and not repeated?

  • 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-29T04:15:58+00:00Added an answer on May 29, 2026 at 4:15 am

    I’d recommend following the pattern introduced by Paul Irish for Markup-based unobtrusive comprehensive DOM-ready execution. There’s a number of side benefits to the approach such as encapsulation, namespacing, etc., but the chief benefit for you would be conditional execution of JavaScript based on a id or class on <body>.

    So in your base template change your <body> tag to something like the following:

    <body class="{% block body_class %}{% endblock %}">
    

    Then, for templates that need maps just do:

    {% block body_class %}{% if block.super %}{{ block.super }} {% endif %}maps{% endblock %}
    

    That looks a little complicated, but all it’s doing is inheriting from the values any parent templates set for that block. The if block is used to conditionally include the space needed between multiple classes.

    Finally, in your JavaScript you simply create a module for “maps” as the article describes and put all your map-specific JS there.

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

Sidebar

Related Questions

I have a CSS entry that looks like this: .header { background-image: url(./images/embouchure.jpg); background-repeat:
I have created a button CSS class that uses background images with different positions
I have a header that has a css background image that I want to
I have heard that ID is unique and can only be used once in
I have a CSS like this ul { list-style-image:url(images/bulletArrow.gif); } ul li { background:
If I have two css files: File 1: .colorme { background-color:Red; } File 2:
I have this background, the css code is: body { background: #FFF url('images/bg.png') no-repeat
I have html and css as below - .title { display: block; background-color: red;
i have the following script css: img { background-image:url(man.png); background-repeat:no-repeat; padding-top:6px; padding-bottom:60px; padding-left:10px; padding-right:10px;
I have given a table background image using css background-image property. The cells are

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.