Path in src to reach a file in a different directory - javascript

I have a folder called projects and in it I have a game folder and an engine folder. I have my engine.js file inside the engine folder and I was wondering if I could access it with my game.html file from the other folder like so
<script type ="text/javascript" src ="\engine/engine.js"/>
Now, obviously the above doesn't work, but what I need to do is go back out of the game folder to the project folder and then into the engine folder.
File tree: projects folder
projects
engine
engine.js
game
game.js
What is the proper format for src to provide users with a link to engine.js?

Use a double-dot to go back:
src="../engine/engine.js"

That would be:
<script type ="text/javascript" src ="../engine/engine.js"/>

Related

laravel asset() doesnt find assets in public

I already put the folder named assets in my public folder and I should be able to access the assets like described on this page: https://laravel.com/docs/9.x/helpers#method-asset
But for some reason It wont load and the browser console gives this error:
Loading failed for the “http://localhost:8000/assets/js/jquery-3.4.1.min.js” when this should be the exact path
In the blade file I wrote this:
<script src="{{asset ('assets/js/jquery-3.4.1.min.js') }}"></script>
I already tried with URL::asset and It doesnt find the file
I made the symbolic link 'links' => [ public_path('storage') => storage_path('app/public'),
The real path of the file is /home/penta/ponti-gest/storage/app/public/assets/js
In my page I am using http
Based on your comments:
I already have the folder assets in my public/storage folder
#GiuseppeP. Is the public/storage folder a symbolic link?
yes I made the symbolic link 'links' => [ public_path('storage') =>
storage_path('app/public'), ],
Your file is in the storage path.
This is accessible by using:
storage_path()
The storage_path function returns the fully qualified path to your
application's storage directory. You may also use the storage_path
function to generate a fully qualified path to a given file within the
storage directory:
storage_path('app/public/assets/js/jquery-3.4.1.min.js')
Addendum
Alternatively, you can use the asset() helper by prefixing the path with storage/.... I.e:
The Public Disk
The public disk included in your application's filesystems
configuration file is intended for files that are going to be publicly
accessible. By default, the public disk uses the local driver and
stores its files in storage/app/public.
Once a file has been stored and the symbolic link has been created,
you can create a URL to the files using the asset helper:
asset('storage/assets/js/jquery-3.4.1.min.js')
method asset() meaning go inside public folder
so if it doesn't work
<script src="{{asset ('assets/js/jquery-3.4.1.min.js') }}"></script>
you should have in public folder assets folder then js folder
then the file jquery-3.4.1.min.js
hopefully that help you
you must set ASSET_URL in your .env file.
then run
php artisan config:cache

EJS File having trouble finding script file after converting JS project to Typescript

Folder structure:
root:
dist:
FOLDER 'models' (models for mongoose/mongodb)
this is also where I store the Typescript compiled JS files, such as script.js.
src
FOLDER 'models' files to be compiled for mongoose models
FOLDER 'assets' (photos, thumbnails, etc)
FOLDER 'css' (for the entire project)
This is where these files live: server.ts, script.ts, and other misc scripting files that all get compiled by typescript.
FOLDER 'views':
EJS layouts and body files. For example, layout.ejs and home.ejs (body of layout.ejs)
also at root are: package-lock.json, .env, .gitignore, package.json, and tsconfig.json
Now onto the problem i'm facing...
I'm very new to Typescript but was able to convert many of these files including server.js and script.js (the main two files of this program) to Typescript. They currently have no errors pre-compilation, but the home.ejs file (in views) can not find the script.js file.
When using in my ejs files, should i aim to the script.js that has been compiled down? Or should I aim to the script.ts in my src folder? I was able to link to the script.js but when I converted the file to TS, the EJS file can no longer find it in browser.
Here is the code that is relevant for my home.ejs file:
<body>
<script src="/dist/script.js"></script>
<script src="/launch.js"></script>
</body>
And here is a screenshot, if it helps, of my current structure:
Image of folder structure
For the line, I have tried all of these but they don't work:
<script src="/dist/script.js"></script>
<script src="./dist/script.js"></script>
<script src="../dist/script.js"></script>
<script src="../../dist/script.js"></script>
Also knowing if node should run the server.js (compiled) file or the server.ts (uncompiled) would be helpful!

How to src to a file in a folder within a folder

Hi I'm pretty new to HTML and JavaScript and I was wondering how to src to a file in a folder within a folder?
Any help would be appreciated.
To be more specific I'm trying to access a JavaScript library in a folder named yui and which is another folder named libraries.
<script src='./folderwithinfolder/file.js'></script>
To break it down:
./ = folder this file is in.
folderwithinfolder/= A folder within the folder the webpage is in.
file.js = Javascript File.
You can change the SRC to follow where you want to go the folders:
libraries/yui/your-library-name-here.js

How to get the javascript file (JS) path which is stored in application bundle to html file which is there in document directory

I have one .js file named final.js which I copied as bundle resource I have a requirement like the html document which reads this js file should download at runtime and store it in documents directory. But the js file is not able to read by the html when I loaded it in webview, because of the path of .js file.
I tried with the solution like below, but not worked.
<script src ="./final.js"> </script>
And finally I tried to copy the hardcoded path of application bundle like below, now it worked. Finally I come to know that the path is not proper.
> <script src ="/Users/unknownUser/Library/Application Support/iPhone
> Simulator/7.0/Applications/025EF3B6-F2E6-4162-8921-839D7D98FF58/HTMLGetdataTestApp.app/final.js">
> </script>`
Can any one tell me that how a html file which is stored in documents directory can read a .js file which is stored in main bundle with the correct path instead of hardcoded like above.
The simple solution will be copying the final.js file to documents directory.
Copy the js file from bundle to the document directory (where the html page is located) and set the path as:
<script src ="final.js"> </script>

Pointing to files on my server

I'm having some difficulty pointing to one of my JS files on my server. I have a pretty standard set up:
index.html
js folder
css folder
The difficulty is I have another folder called
6_toggle
Within this folder I have six HTML files named 1.html, 2.html, etc. I need these individual files to point to a file in my JS folder. I thought it would be:
<script src="../../js/view.min.js?auto"></script>
I've also tried:
<script src="../js/view.min.js?auto"></script>
But it doesn't seem to work. Would anyone have any ideas on how to fix this?
Assuming your tree structure looks like this:
-index.html
-js_folder
-css_folder
-6_toggle
-1.html
-2.html
-etc
from index, you first need to reach into the js folder, then the file.js like so:
<script type="text/javascript" src="js_folder/file.js"></script>
from within your 1.html and 2.html files, you'd access the file like so:
<script type="text/javascript" src="../js_folder/file.js"></script>
You must first reach into the parent folder, then down into the js folder for its children
When you have this structure
root/
-index.html
-js_folder
-css_folder
-6_toggle
-1.html
-2.html
-etc
You can access js_folder any time with <script type="text/javascript" src="/js_folder/file.js"></script> <- I think this is a best practice for accessing file asset on server. By include root, you can fotget how many .. needed to go back

Categories

Resources