You don't need that at Inference time. It's for training purposes.
You can skip these Layers while exporting to JavsScript. These layers do not have weights.
On this example [Link], which has these Layers, I removed these layers and it worked fine.
# Added this code to remove the first 4 Aug layers
input = model.input
model_export = input
for layer in ...
There is no rule that only mean or median should be used. Based on the situation sometimes mean is better and sometimes median. In fact there are occasions when mode would be better.
These are not the only techniques to fill NaNs. There are several other imputation methods. If you are starting out, then an excellent hands-on training material would be the ...