How does Apache load Javascript files? - Stack Overflow

I was creating a simple Wordpress plugin which uses a javascript file. Although the PHP edits did not n

I was creating a simple Wordpress plugin which uses a javascript file. Although the PHP edits did not need a server refresh and were reflected immediately on page reload, the javascript edits were not reflected until I restarted the server (they did not work even on a hitting "Refresh" on xampp).

What I would like to know:
1. How are Javascript files are loaded in Apache?
2. Is there anyway to configure it so that the files are loaded everytime I reload the page? ( I will be editing the Javascript files a lot. I do not want to be restarting the server everytime!)

I was creating a simple Wordpress plugin which uses a javascript file. Although the PHP edits did not need a server refresh and were reflected immediately on page reload, the javascript edits were not reflected until I restarted the server (they did not work even on a hitting "Refresh" on xampp).

What I would like to know:
1. How are Javascript files are loaded in Apache?
2. Is there anyway to configure it so that the files are loaded everytime I reload the page? ( I will be editing the Javascript files a lot. I do not want to be restarting the server everytime!)

Share Improve this question asked Jan 23, 2012 at 1:59 SamudraSamudra 1,2331 gold badge16 silver badges22 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

How are Javascript files are loaded in Apache?

Ans: It is the same with your html file or other static contents.

Is there anyway to configure it so that the files are loaded everytime I reload the page?

Ans: This is not the problem of Apache, It is mostly because your browser caches your javascript file. Simply clear your browser caches.

A nice trick you can do is to append a random string to the resource that you want to keep up to date every pageload. Ex.:

<script type='text/javascript' src='/myScript.js?p=<?php print sha1(time()); ?>'>
</script>

In the same way, if you want to always refresh an image, just append it a random parameter:

<img src='/images/myImage.png?p=<?php print sha1(time()); ?>' />

You can do this with CSS files too.

Appending a random parameter to a resource will make the browser treat this resource as a new one, so it can't be loaded from cache.

I use a Firefox add on called "Web Developer" to temporarily disable the browser cache when I am working on web pages. You can toggle the cache on and off with it, amongst other things. I still think Beto Aveiga's plan is very interesting, I am thinking of a scheme to put it to use right now.

GET requests are cached in the browser. Clear your browsers cache and set it to check for new files every time in the browser's settings.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745237813a4617994.html

相关推荐

  • How does Apache load Javascript files? - Stack Overflow

    I was creating a simple Wordpress plugin which uses a javascript file. Although the PHP edits did not n

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信