Hot answers tagged

14 votes
Accepted

Securing ajax calls to rest api

You can't. Let me rephrase: Impossible You could/should make it harder to use a token. Implementing a max-usage per token, a max life-time, ... It is however impossible to know if it is the ...
  • 528
11 votes

Are clean coding rules less relevant for large open source projects?

Just to be clear, Bob did not invent the concept of clean code. He just wrote a book with that title containing some very sound advice and some more dubious advice and opinions. I will bet all ...
  • 55.2k
8 votes

Are clean coding rules less relevant for large open source projects?

... people want line by line explanations for why a particular approach was used ... Can you can read and understand what the code does? You don't need comments. Do you understand why the code ...
  • 11.7k
7 votes
Accepted

WebForms, JQuery and the DRY principle

A colleague I'm working with insists this is WET code and a violation of the DRY principle since each page has to load JQuery individually. No. The jQuery library code is cached by the browser. If ...
7 votes
Accepted

How to process large image with a minimum time lag

I cannot and will not recommend any libs or frameworks for this, but if you are willing to implement a system by yourself, here is a simple outline of what might work: send the image to the server ...
  • 188k
6 votes
Accepted

I keep bouncing from "god function" to "tiny SRP functions" how do I break this cycle?

What you need is a new abstraction. Simply pulling out common bits of functionality ends up creating a mess. You need to find a brand new way of looking at your problem that enables you to extract ...
5 votes

Securing ajax calls to rest api

I need for my app to consume a rest api service and since I will call it from javascript/jquery i need to expose it to the end user That's your first mistake. As Pinoniq pointed out in his answer, ...
5 votes

How can I keep browser URL secret when editing data?

I have encountered this issue several times and have found what I think is the simplest solution. Since your user can edit (personal/account?) information, I assume you have some kind of ...
5 votes

How to write JavaScript while keeping HTML/CSS out of it

Use a mvw (model/view/whatever) pattern model: "pure" javascript library modelling abstract concepts. This part usually contains objects & methods names related to the application domain (car ...
  • 7,832
5 votes
Accepted

Why JS MVC frameworks prefer data binding to UI element reference?

The purpose of data binding is to decouple the view from the model. Neither the model nor the view should know about each other. Data binding is the glue that connects the model to the view and ...
4 votes

Is jQuery an example of "god object" antipattern?

$ is not an object, it's a namespace. Would you call java.lang a god object because of the many classes it contains? It's absolutely valid syntax to call java.lang.String.format(...), very similar in ...
4 votes

how can I minimize my ajax calls to the server while creating a dashboard

You could build API aggregation/de-aggregation layers on both ends. On the client-side, you can build a layer that receives API requests and "holds" them for N ms to see if up to M other requests ...
  • 13.2k
4 votes
Accepted

Auto-save user input - the smartest way?

Have a save button. There are very good reasons why applications use explicit save/submit buttons: Gives the user a chance to change their mind about the edit. Unless you provide some sort of undo ...
  • 4,818
4 votes
Accepted

How to merge two functions that do same things with different variables

You cannot write only one function. You will still need to have a separate function for each event handler, so the best you can do is to have 3 functions whose total amount of code will be less than ...
  • 31.5k
4 votes
Accepted

Using SessionStorage to keep client side state

Although using server side session state to store user data between page loads works, the downside is it eats memory on the server per user. So its not scalable. keeping data in a cookie, although it ...
  • 65.5k
4 votes
Accepted

How does jQuery work?

A high-level dissection of the code posted: <script type="text/javascript"> Html-element to embed a script in it $("#circle") $ is the jQuery alias for getting the jQuery object which wraps ...
  • 347
4 votes

Hosting a static website containing JavaScript/jQuery

There is a difference between hosting static .js files that are served to clients, and running a JS program on the server to generates dynamic files in response to requests. The services you are ...
  • 10k
4 votes

How to impersonate user in web app?

Update to your update. So I am looking at building something into my web page that allows the business user to pick an end user from a list of names, then pass that login name along to the web ...
  • 38.7k
3 votes

How can I keep browser URL secret when editing data?

Just use an URL with some query parameters, like <a href="user/5?checksum=12345">Edit</a> Of course the checksum is computed, perhaps using some session cookie, and your server code has ...
3 votes
Accepted

Storing session key in a hidden field

Cookies are primarily attractive because of the ability to store long-lived values and the convenience of not having to explicitly submit session identification with each request (because the browser ...
  • 13.2k
3 votes

Attempting to make a Cross Domain AJAX request to a Server I don't own

What I would do: Contact the 3rd party site, and ask if they could include you in their CORS policy, if not then Make sure there's no JSONP or similar "public access" point to use, if not then Use a ...
  • 347
3 votes

Auto-save user input - the smartest way?

Use a button It is what users expect, don't discount the value of a familiar interface. It gives the users the control they need, including the power to not publish something if they change their ...
  • 1,056
3 votes
Accepted

(jQuery) What is wrong with methods such as .append?

What they probably meant is that manipulating the DOM is slow and that you can avoid injecting HTML through jQuery. What you can do, instead, is to have A/B variants both in your original HTML. Then, ...
3 votes
Accepted

Does IE have more strict Javascript parsing than Chrome?

You were using an old version of jquery, as you admitted. The browser detection in that version was broken and so didn't define the global '$' jquery object. So when you tried to use it, it was not ...
  • 146
3 votes

Is jQuery an example of "god object" antipattern?

Benjamin asked me to clarify my position, so I edited my previous post and added further thoughts. Bob Martin is the author of a great book titled as Clean Code. In that book there is a chapter (...
  • 1,151
3 votes

Declaring many times: script type="text/javascript"

Your script blocks are not likely having the effect you are expecting, since javascript scope rules do not work that way. Scripts in one block can absolutely affect scripts in another block, if the ...
  • 10.8k
3 votes
Accepted

Changing CSS classes when different strings are displayed in a text element with jQuery

I believe it is the jQuery contains predicate you are looking for. It lets you search a string to find only nodes that contain a given string. Assuming your items for sale have class item, this code ...
3 votes
Accepted

Would it be the right software engineering system to move from AngularJS-based to jQuery-based or hybrid implementation for webapp?

Most of the time you can achieve your goal with any technology, so your question is "Should I stick with jQuery that I know well or take the time to learn AngularJS". If you are looking short term and ...
  • 146
3 votes
Accepted

Rendering partial View in MVC

There are two times when you want to render a partial view: Synchronously, as part of rendering a larger view e.g. the view that is called when rendering /Widgets/Details/ might have Razor code that ...
  • 146
3 votes
Accepted

Using CSS classes to express state

Using classes to track state is pretty common, for example - in AngularJS: https://docs.angularjs.org/api/ng/directive/form#css-classes but - remember that css-classes are easily manipulated in the ...

Only top scored, non community-wiki answers of a minimum length are eligible