Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

JS files copied to assets - why?


Go to End


10 Posts   4324 Views

Avatar
mjpg

8 Posts

24 July 2009 at 2:47am

Three .js files are being copied to the assets folder - they are:

base.js /****** FILE: jsparty/prototype.js *****/
cmsmain.js /****** FILE: cms/javascript/CMSMain.js *****/
leftandmain.js /****** FILE: jsparty/loader.js *****/ + others

I don't want users to see these, and I don't know why they are there?

All I have done to a clean install of 2.3.2 is to create two new folders in assets/Uploads and upload one PDf and one JPG.

Any ideas? Thanks in advance.

Avatar
schellmax

Community Member, 126 Posts

24 July 2009 at 3:35am

silverstripe combines javascript files for the purpose of faster loading.
see cms/code/LeftAndMain.php, i.e. at around line 260 some js files are combined in 'assets/base.js'.
the reason silverstripe chooses the assets folder i think is that it's a folder that needs to be writeable by the standard requirements.
it should be possible do set it to another folder (don't forget to make it writeable using chmod) but you have to take care of other code expecting these files in the assets folder.

Avatar
mjpg

8 Posts

24 July 2009 at 4:02am

Thanks very much for the reply - I understand.

Do you know why the developers choose to put these files in a folder that users can see?

Avatar
AlexBeka

Community Member, 21 Posts

2 October 2009 at 11:44pm

Edited: 02/10/2009 11:45pm

my workaround for this "issue" is to hide files with the extension .js and .html (for the 404 page generated files), and therfore i put the following code at the end of the constructor of AssetTableField.php;

//hiding .js and .html files which are auto-generated by SS by default in /assets folder
$this->sourceFilter .= ($this->sourceFilter) ? " AND " : "";	
$this->sourceFilter .= "(`Filename` NOT LIKE '%.js' AND `Filename` NOT LIKE '%.html')";

it´s not a special or elegant solution but it solves this issue for me;

Avatar
Web Designer Perth

Community Member, 49 Posts

27 October 2009 at 10:32pm

Please will you share exactly where these lines go?

TIA

Avatar
AlexBeka

Community Member, 21 Posts

27 October 2009 at 10:44pm

just put these lines at the end of the constructor (function __construct in /cms/code/AssetTableField.php)

Avatar
Web Designer Perth

Community Member, 49 Posts

27 October 2009 at 11:01pm

Thx so far Alex,

I can see that line but I really don't have a clue where the 'end of the constructor' is :(

Avatar
AlexBeka

Community Member, 21 Posts

27 October 2009 at 11:20pm

well, that is my changed AssetTableField constructor:

function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
		parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
		
		$SNG_file = singleton('File');
		
		// If search was request, filter the results here
		$SQL_search = (!empty($_REQUEST['FileSearch'])) ? Convert::raw2sql($_REQUEST['FileSearch']) : null;
		if($SQL_search) {
			$searchFilters = array();
			foreach($SNG_file->searchableFields() as $fieldName => $fieldSpec) {
				if(strpos($fieldName, '.') === false) $searchFilters[] = "`$fieldName` LIKE '%{$SQL_search}%'";
			}
			$this->sourceFilter = '(' . implode(' OR ', $searchFilters) . ')';
			$this->searchingFor = $_REQUEST['FileSearch'];
			
			// @todo Integrate search form more closely and don't rely on deprecated
			//  $extraLinkParams.
			$this->extraLinkParams = array(
				'FileSearch' => $SQL_search
			);
		}		
		
		//hiding .js and .html files which are auto-generated by SS by default in /assets folder
		$this->sourceFilter .= ($this->sourceFilter) ? " AND " : "";	
		$this->sourceFilter .= "(`Filename` NOT LIKE '%.js' AND `Filename` NOT LIKE '%.html')";
		
		$this->sourceSort = 'Title';
		$this->Markable = true;
	}

Go to Top