0

I have a php file, content.php, which includes a another php file, viedo.php. Inside video.php i use a script tag to do some javascript stuff for displaying a video. I was wondering if i were to put the script into an external javascript file, would that file be cachable, and if so, is this bad/good practice? My thinking is, since php builds the page when you navigate to the url, im not sure if the browser will be able to tell if the javscipt file was cached.

content.php

<?php
include 'nav.php';
 // ...
include 'video.php';
 // ...
php include 'footer.php';
?>

video.php

<div>
<div id="myDiv">This text will be replaced with a player.</div>
<script>
jwplayer("myDiv").setup({
    "file": "http://example.com/myVideo.mp4",
    "image": "http://example.com/myImage.png",
    "height": 360,
    "width": 640
});
</script>
</div>
3
  • 2
    It's always better to place all javascript that can be cached in external files. The browser caches external files unless you send specific heathers so that the content would notbe cached. Commented Jan 3, 2018 at 16:06
  • We don't know the overall architecture of your app but the browser doesn't care about file extensions (plus they can be easily hidden anyway). Commented Jan 3, 2018 at 16:07
  • If that's all the JavaScript you're going to be using, there's minimal benefit to caching it, and the extra HTTP request for the .js file is likely to set you back more than you gain. Commented Jan 3, 2018 at 16:09

1 Answer 1

2

Yes it will be cached and yes it is a good practice.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.