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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:36:34+00:00 2026-06-17T08:36:34+00:00

I have a simple js file: //base.js … var url = ‘/post/’ + id

  • 0

I have a simple js file:

//base.js

...
var url = '/post/' + id + '/comment';
...

I’m using Symfony2 so on the server side all the urls are generated by the Router, and it bugs me that I use hardcoded urls in the js..

Is there a way to make them more dynamic?
Those are the solutions I thought about but I’m not happy with:

  • Defining them in the HTML tags like <div data-url="<?php path('post_comment'); ?>">
  • Defining them in an inline script tag <script language="text/javascript">...</script>

I think that the urls in the js files of some big sites (SO, GitHub, etc.) are hardcoded, am I right?

  • 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-17T08:36:35+00:00Added an answer on June 17, 2026 at 8:36 am

    Friends of Symfony JS Routing Bundle was made exactly for your needs

    var url = Routing.generate('some_route_to_expose', { foo: 'bar' });
    // url is http://somehost.com/app_dev.php/my_route
    

    The bundle also lets you dump, compile and minify the resulting javascript. Its great!

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

Sidebar

Related Questions

I have a simple set of urls in a Django url conf file which
I have a simple grails file upload app. I am using transferTo to save
I have this simple base class (Module): package XMSP::File; use parent 'IO::File'; sub new
I have a simple file read and write function. private void WriteToFile(String filename, String
I have a simple file browser and there I display files and folders, obtained
I have a simple file-system-ed-login (not mysql) just to track number of users who
I have a simple .dot file (graphviz), see below: digraph Mapper{ Mapper [label=Mapper]; General
I have a simple batch file sitting in my windows system - @echo off
I have a simple JavaScript file that has three jQuery $document.ready functions. All three
i have a simple xml file in a wcf service that i am trying

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.