DEV Community

Willem de Beer
Willem de Beer

Posted on

Always learning together.

Hi I'm Will. I've been messing with markup and script for years. Pretty much on my own though. I'm not part of a team of developers so I'm here to formulate what is missing when working alone - I want to be able to grow my knowledge even further in return for offering others what I already know well - to continue learning together. I joined to get answers to coding problems more quickly and in return offer my own experience in making websites responsive and how I achieve my aim of creating sites that are fully W3C valid, streamlined and device responsive. I look forward to sharing code ideas.

Top comments (8)

Collapse
 
willemdebeer profile image
Willem de Beer

My first question is as follows:

Passing a variable works in this scenario - ./filename.php?variable=1

It however fails with a js file - ./filename.js?variable=1

Someone please point out the obvious, I'm stuck :/

Collapse
 
elanatframework profile image
elanatframework

Can you provide a scenario where you need to statically call a script file with a query?

This is done under the server and can be implemented with url rewrite or middleware or other.

The existence of a query string also eliminates the need to mess with the cache.

Usually, the JavaScript file needs to be created dynamically for languages, user personalization items, etc. (of course, it is not recommended to use external scripts).

Example
Url: example.com/script/language.js/?value=en

        // Site Language Variant
        var LanguageVariant = new Object();

        LanguageVariant.ConnectionError = "connection error";

        LanguageVariant.Okay = "okay";

        LanguageVariant.No = "no";

        LanguageVariant.Friday = "friday";

        LanguageVariant.JavascriptIsDisableMessage = "javascript is disable";

        LanguageVariant.Monday = "monday";

        LanguageVariant.Saturday = "saturday";

        LanguageVariant.Sunday = "sunday";

        LanguageVariant.Thursday = "thursday";

        LanguageVariant.Tuesday = "tuesday";

        LanguageVariant.UseCookieMessage = "this site use cookie";

        LanguageVariant.Wednesday = "wednesday";
Enter fullscreen mode Exit fullscreen mode
Collapse
 
willemdebeer profile image
Willem de Beer

Thank you Elanatframework. With regard to the 'example.com/script/language.js/?value=en' does a slash always have to be added between .js and the'?'. In other words this example would not work - example.com/script/language.js?value=en (no forward slash)? Please bear in mind I know very little about coding at this stage... lots still to learn :)

Thread Thread
 
willemdebeer profile image
Willem de Beer

Just tried the following:

domain.com/file.php?variable=var --- this works (difference is php)

domain.com/file.js?variable=var --- this fails (difference is js)

domain.com/file.js/?variable=var --- this fails (difference is js/)

Thanks
Will

Thread Thread
 
elanatframework profile image
elanatframework

Dear Willem de Beer
I apologize for the mistake in the extra slash and confusion!
This link example.com/script/language.js?value=en is standard and correct.
This example is related to server codes.
In fact, a programming language (such as PHP or Python, etc.) on the server creates this language.js file virtually.
The language.js example is a special example and you usually don't need to do this.
HTML, JavaScript, and CSS run in your browser. The addition of ?value=en is to send the value of en from your browser to the server.
You don't need to send data to JavaScript as a query. JavaScript can read the query string from anywhere it is executed and there is no need to do this.

Collapse
 
anitaolsen profile image
Anita Olsen • Edited

Hello Will! Welcome to our wonderful community! 😊 I am the unofficial welcome committee but you can just call me Anita 😁

Collapse
 
willemdebeer profile image
Willem de Beer

Hi Anita. Thank you.

Collapse
 
rickrickiin profile image
Rickrickiin

Learning together is always better.