Message from JavaScript discussions

October 2020

— And make sure to have cache headers?


Or with HTTP2 server can just push the scripts, so it doesn't really matter when you set the script tag

— True, but I am already thinking about dropping the main optimization which caused all the other issues. I just wanted to have target based bundles for the custom js code, but that fucked up all the legacy stuff as my scripts are dynamically added based on feature detection

Message permanent page

— I want to trigger php function using javascript but not working

— Can you share the code in plain text? using pastebin or hastebin

— <?php
function change(){
header("location: register.php");
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
.box {
height: 100px;
width: 100px;
background-color: green;

<div class="box" onclick="my()">
<button>Click me</button>

function my() {
var trigger = <?php change(); ?>

Message permanent page

— You cannot call a php function from javascript.

— Php is a server. It serves data via HTTP.

— Here you use javascript on the browser (client-side) to interact with the user

— Then what is the way

E.g. you have a file change.php that does what you need, with javascript you can dynamically retrieve the content and display it.


const change = async () => {
const response = await fetch('/change.php')
const text = await response.text()
document.querySelector('#content').innerHTML = text

Message permanent page

— Will I get my desired result