Tag: tips-and-tricks

Javascript development Cache headers in Apache

During development of a javascript webapp I found that the updated javascript was not picked up by my webbrowser. Even using ctrl+F5 would not always work to refresh the files. In order to make development easier I added the following cache headers to the Apache VirtualDirectory configuration in order to make the browser always fetch the latest version of the file from my development server.

<FilesMatch "\.(html|htm|js|css)$">
    FileETag None
    <ifModule mod_headers.c>
        Header unset ETag
        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </ifModule>
</FilesMatch>

Leave a Comment

Concatenate files under Windows

Recently I found the need two concatenate two javascript files in a build script under Windows. Using Linux concatenating two different files is easy using the cat command. It turns out that using Windows it is also trivial.

copy /b script1.js+script2.js combined.js

That’s it, really easy. The /b operator is added to let copy handle the files as binary files, for safety reasons.

If the destination file already exists, copy will prompt to overwrite. This prompt can be set to Yes by default by adding the /y option.

copy /b /y script1.js+script2.js combined.js

When combining files from different folders, e.g. ..\script1.js+.\htdocs\script2.js make sure you are using backslashes and not forward slashes in the path.

Leave a Comment

PHP Whitespace check

Did you ever find yourself with unwanted whitespace at the start or end of your document? A tip to prevent this beforehand is to never close the PHP file with a _?> _tag. These tags are not required. It is a common practice on several projects.

If this is too late and you do have whitespace, execute the snippet below in the root folder to find the culprit.

<?php
foreach (glob('\*\*/\*.php') as $file){
	if (preg_match('/\?'.'>\s\s+\Z/m',file_get_contents($file)))
		echo $file . PHP_EOL;		if( preg_match('/^[\s\t]+<?php/', file_get_contents($file)) )
		echo $file . PHP_EOL;
}

This code will match both the whitespace starting before the open and after the close tag.

Leave a Comment